Skip to content

Instantly share code, notes, and snippets.

@hivelogic2018
Created August 21, 2025 17:47
Show Gist options
  • Select an option

  • Save hivelogic2018/1b43ffb7c2afc870118e2bae8bd8db6e to your computer and use it in GitHub Desktop.

Select an option

Save hivelogic2018/1b43ffb7c2afc870118e2bae8bd8db6e to your computer and use it in GitHub Desktop.
Traefik advantage

explain traefik dynamic service discovery ? meaning working with docker services, I don't need to restart traefik container? fair to say, essentially, changes of labels for portainer, forgejo services, don't require a restart on traefik? any other benefits traefik dynamic service discovery offers besides that?

Yes, it is fair to say that with Traefik's dynamic service discovery, you don't need to restart the Traefik container when you add, remove, or change labels on other Docker services like Portainer or Forgejo. This is a core feature that makes it a "cloud-native" reverse proxy.

How It Works

Traefik works by acting as a proxy and a watcher. 🧐 It connects to the Docker API and constantly monitors for changes in the container's state. When you start, stop, or update a container with the appropriate Traefik labels, Docker emits an event. Traefik listens for these events and instantly reconfigures itself in memory without needing a restart. It reads the labels from the new or changed container and automatically creates the necessary routing rules (routers, services, and middlewares) on the fly.

This process is broken down into two main types of configuration:

  • Static Configuration: This is the configuration for Traefik itself, defined when the container starts. It includes things that rarely change, like entry points (the ports Traefik listens on, e.g., 80 and 443) and which providers (like Docker) it should use for dynamic configuration.
  • Dynamic Configuration: This is the configuration that changes frequently, like the routing rules for your services. This is what Traefik discovers from the Docker container labels.

The key benefit is that the dynamic configuration is reloaded in real time, so any changes to your services are reflected immediately.


Other Benefits of Dynamic Service Discovery

Beyond avoiding restarts, Traefik's dynamic service discovery offers several other significant benefits:

  • Decentralized Configuration: The routing logic is defined directly on the containers themselves using labels. This decentralizes the configuration, making it easier to manage a large number of services. A developer can spin up a new service with the correct labels, and Traefik will automatically handle the routing, without requiring a change to a central configuration file or manual intervention from an Ops team.
  • Simplified Deployment: It simplifies your deployment workflow. You can deploy new versions of services or add new microservices, and Traefik will automatically handle the routing for them, making CI/CD pipelines more efficient and reducing the chance of human error.
  • Built-in Load Balancing: Traefik automatically acts as a load balancer for services with multiple running instances. When you scale up a service by increasing the number of replicas, Traefik detects the new containers and automatically distributes incoming requests among them, all without any additional configuration.
  • Automatic HTTPS: Traefik can automatically handle the entire process of obtaining and renewing SSL/TLS certificates from providers like Let's Encrypt for all your services. All you have to do is add a few labels to your container, and Traefik will secure the connection for you.

traefik vs caddy footprint, specs, perf, ease of setup?

While both are excellent modern reverse proxies written in Go, Traefik is a better fit for complex, dynamic, and cloud-native environments, while Caddy is the superior choice for simplicity and ease of use, especially for single-host setups.


Footprint & Specs

Since both are written in Go, they generally have a higher memory footprint compared to C-based proxies like Nginx. However, this is often negligible for most use cases, especially given modern server resources.

  • Caddy: Has a very minimal footprint when used as a reverse proxy for a few sites. It's a single static binary with no external dependencies, which makes it incredibly easy to deploy.
  • Traefik: Can be more resource-intensive due to its more complex architecture and built-in features like a web UI and dynamic service discovery providers.

Performance

General benchmarks often show that both Caddy and Traefik perform well, but may lag behind Nginx in terms of raw throughput and low-latency scenarios. In a head-to-head comparison, performance can vary depending on the specific workload.

  • Caddy: Is known for its efficient handling of HTTPS traffic. It can be a very fast static file server and a capable reverse proxy.
  • Traefik: While also high-performing, it's designed more for the unique demands of a dynamic containerized environment, where it excels at reconfiguring itself quickly. Its performance advantage lies in its ability to adapt on the fly, not necessarily in raw speed.

Ease of Setup

This is where the two solutions have their most significant differences.

  • Caddy: Is widely praised for its simplicity. Its configuration file, the Caddyfile, is designed to be human-readable and straightforward. The automatic HTTPS setup is its most notable feature, handling SSL certificate acquisition and renewal with zero configuration, truly making it a "set and forget" solution for basic use cases.

  • Traefik: Can be more complex to set up initially. Its configuration, typically in YAML or TOML, is more verbose. However, its real strength is its dynamic service discovery. For Docker or Kubernetes, you can configure Traefik with simple labels directly on your containers, and it will automatically create the reverse proxy rules. This makes it incredibly easy to manage a large number of microservices, as you don't need to manually update a central configuration file every time a new service is added or removed.

You can learn more about the pros and cons of these different reverse proxies in a video that compares Nginx, Traefik, and Caddy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment