HashiCorp Consul
medium 32 minConsul keeps a live list of services and their health across many machines, answers where a service is over DNS and HTTP, stores small settings and locks, and can decide which service may call which through a service mesh.
Video lesson · Chapter 1 of 5
Another payments till joins the market
Consul in 90 seconds
1:30Reel coming soon
Theory
Read or listen first. About 2 min.
What it is
When programs start and stop all day, their addresses change all day. Consul is a system that keeps the current list, called the catalog: which services exist, where each copy runs, and whether it is healthy. Callers ask by name. The general idea is explained in service discovery; this page is about the product.
Consul is one program that runs in two roles. A few servers hold all the data and agree on it. A client agent on each machine registers the services there, checks their health, and answers questions from local programs. On top of the catalog Consul offers a key/value store, locks, and a service mesh: proxies that encrypt calls between services and allow or deny them by name.
Why it exists
A settings file with addresses is wrong as soon as a machine is replaced. A load balancer in front of every service costs money and adds a hop. Consul makes the list automatic: a service registers when it starts, and a copy that fails its check leaves the answers.
Kubernetes has its own discovery inside one cluster. Consul is chosen when the estate is wider: virtual machines, bare machines, several clusters, several datacenters, all needing one set of names and one set of rules about who may call whom.
A short history
2014, April
Version 0.1.0 is released on 17 April, according to the project's changelog.
2017, October
Version 1.0.0 is released on 16 October.
2018, June
Version 1.2.0 brings a beta of Connect, the service mesh: automatic TLS and permission by service identity.
2022, November
Version 1.14.0 turns cluster peering and the mesh on by default. Consul on Kubernetes stops needing a client agent on every node and uses Consul Dataplane.
2023, August
HashiCorp announces on 10 August that future releases move from the Mozilla Public License 2.0 to the Business Source License 1.1.
2025
IBM completes the purchase of HashiCorp on 27 February. The hosted HCP Consul Dedicated service ends on 12 November.
2026
Version 2.0 starts IBM's numbering, with a new major version in April and a feature update in October. 2.1.0 follows on 21 October.
Words to know
- Agent
- The Consul program running on a machine, as a server or as a client.
- Catalog
- The list of nodes, services, addresses and check results, kept by the servers.
- Datacenter
- One Consul cluster: a set of servers with their own catalog, and the agents that belong to it.
- Gossip
- Agents telling a few other agents what they know, so that news of members and failures spreads without a centre.
- Raft
- The agreement method the servers use. A change counts once a majority has stored it.
- Blocking query
- An HTTP request that waits until the answer changes or a time limit passes.
- Intention
- A rule that allows or denies calls from one named service to another.
- Session
- A contract tied to a node or a time limit. Locks belong to a session and are freed when it ends.
How it works
Step through the idea, or press Play.
Register. The local agent adds the service and its checks
Understand it
Start here
The harbour board
Picture a harbour where ships come and go. Nobody can remember who lies at which berth, so the harbour keeps a board, and each ship's mate looks after their own line on it.
Knowing where a ship is and being allowed aboard are two separate questions. Consul can answer both.
The idea
Four jobs in one program
What Consul does
Discovery and health
A live catalog, checks run beside the service, answers over DNS and HTTP.
Service mesh
Envoy proxies beside each service: mutual TLS, intentions, traffic rules, metrics.
Settings and locks
A small key/value store with watches, sessions and leader election.
Many datacenters
Names and failover across places, through WAN federation or cluster peering.
Consul gives you
- One catalog for VMs, containers and bare machines
- Checks close to the program
- Plain DNS, so old programs need no change
- A choice between fast and strictly current reads
- Permission by service identity
Consul does not
- Start or place your programs (an orchestrator does)
- Store application data: a value may be at most 512 KB
- Copy its key/value store to other datacenters by itself
- Turn on access control for you: ACLs are off by default
- Replace timeouts and retries in the caller
Architecture
Servers, clients and two kinds of talk
One datacenter
Who does what
| Part | Job | If it stops |
|---|---|---|
| Leader (one of the servers) | Orders every write and copies it to the followers | The other servers elect a new leader; writes pause meanwhile |
| Followers | Store the log, forward requests, answer stale reads | Nothing visible while a majority remains |
| Majority of servers | Commits writes | No registration, no change. Stale reads can still be answered |
| Client agent | Registers and checks local services, answers local DNS and HTTP, gossips | That machine's services are seen as failed |
| Envoy proxy (mesh only) | Encrypts, checks intentions, balances | That copy loses its mesh traffic |
Two protocols split the work. Raft gives the servers one agreed log; the method is described in etcd. Gossip spreads membership and failures among all agents, see failure detection. Because clients are not part of the Raft group, thousands of them do not slow down agreement.
How many servers may fail
Registering
A service, its check and its exit
service { name = "payments" id = "payments-1" port = 8080 tags = ["v2"] check { http = "http://localhost:8080/health" interval = "10s" timeout = "2s" deregister_critical_service_after = "30m" }}consul reload, or use consul services register.Check types
| Check | How it works | Good for |
|---|---|---|
| HTTP, gRPC, TCP, UDP | The agent calls the program. The default timeout is 10 s | Most services |
| Script | The agent runs a command. The default timeout is 30 s | Special tests; off unless you allow scripts |
| TTL | The program must report in before the time runs out | Jobs without a port |
| Docker | Runs a command inside a container | Containers on a VM |
| Alias | Copies the state of another service or node | A sidecar that follows its service |
From a failed check to a clean list
only_passing is on. Removal happens only if you set a time.Finding
DNS, HTTP and waiting for change
A caller finds a service
Three ways to ask
| Way | Example | Use it when |
|---|---|---|
| DNS | payments.service.consul, agent port 8600 | Any program that can resolve a name; nothing to change |
| HTTP API | /v1/health/service/payments with passing | You need ports, tags, or every copy |
| Blocking query | The same call with index and wait | A proxy or client must learn of changes quickly |
A blocking query hangs until the answer changes. The wait defaults to 5 minutes and is limited to 10. Consul adds up to one sixteenth of the wait at random, so that watchers do not all wake together. If the returned index goes backwards, start again from 0. A return does not prove that something changed.
Consistency
Three read modes
| Mode | Who answers | What you can get |
|---|---|---|
| default | The leader, trusting its lease | Almost always current; rarely stale around an election |
| consistent | The leader, after asking a majority whether it still leads | Always current, slower, more traffic |
| stale | Any server | Fast, scales with servers, works without a leader, may be behind |
Which mode?
Small data
Key/value, sessions and locks
The key/value store holds settings and flags. A value may be at most 512 KB, and one transaction may hold up to 64 operations. Each datacenter has its own store. Think of it as a notice board, with a database elsewhere.
Leader election with a session
Mesh
Who may call whom
The service mesh
Kind = "service-intentions"Name = "payments"Sources = [ { Name = "web" Action = "allow" }, { Name = "*" Action = "deny" }]consul config write. The more exact name wins over the star.Rules are kept in the proxies, so they keep working when Consul cannot be reached. For HTTP services a rule can also look at the path, the method and headers. Changing a rule for plain TCP affects new connections only; those already open are not cut. Envoy itself is covered in Envoy, and other meshes in Istio and Linkerd.
Wider
Several datacenters
| WAN federation | Cluster peering | |
|---|---|---|
| Shape | Several datacenters act as one, with a primary | Independent clusters that trust each other pair by pair |
| Shared | Access rules and configuration come from the primary | Only the services you export |
| Setup | Servers join a WAN gossip pool | One side makes a token, the other presents it |
| Coupling | Higher | Lower; each side can be run by another team |
A prepared query stores a lookup with a failover list: if no healthy copy exists here, ask the next datacenter. Callers use it through an ordinary DNS name. This is failover of names; moving the data is your job, see achieving high availability.
Operate
Ports, limits and the switches to turn on
Numbers to know
| What | Value |
|---|---|
| Servers | 3 or 5 for production |
| Client agents per datacenter | At most 5,000 recommended |
| Server RPC and Raft | Port 8300 |
| Gossip, local and wide | Ports 8301 and 8302 |
| HTTP and DNS | Ports 8500 and 8600 |
| gRPC with TLS | Port 8503 |
| Server memory | 2 to 4 times the working set |
| Raft multiplier | 5 by default; lower means faster failure detection and more false alarms |
Will the lookups fit?
Before production
- 1
Access control
ACLs are off by default. Turn them on with a default of deny, and give each service its own token.
- 2
Encryption
TLS between agents is off by default. Set up the built-in authority, set a gossip key and rotate it.
- 3
Fast disks
Servers are limited by disk for writes and by CPU for reads.
- 4
Snapshots
Run
consul snapshot saveon a schedule, keep it elsewhere and practise the restore. - 5
Watch the leader
Alert on the time to commit, on last contact, and on leadership changes.
Failure
What breaks, and what keeps working
| Failure | What you see | Prepare |
|---|---|---|
| One of three servers | Nothing, after a possible election | Replace it soon: the next loss stops writes |
| Two of three servers | No registrations or lock changes; stale DNS goes on | Five servers across zones; a rehearsed recovery |
| Client agent on one machine | Its services leave the list | Run the agent under a supervisor |
| A wrong health check | Every copy becomes critical and the name is empty | Shallow checks; see failure detection |
| Network split | The side with the majority writes; the other is stale | Callers with timeouts and retries |
Roblox published a detailed report of a 73-hour outage in October 2021. Consul was the shared base for discovery, health checks, locks and Vault. A newly enabled streaming feature caused contention under very high read and write load, and the storage library under Raft behaved badly at the same time. Their lesson applies to every registry: know what depends on it, and make sure monitoring does not.
Decide
When to choose it, and when not
Choose Consul
- Services on VMs, bare machines and containers together
- Several datacenters or clouds with one naming scheme
- Programs that can only use DNS
- Permission between services by identity
- You already run Nomad or Vault and have a platform team
Choose something simpler
- One Kubernetes cluster: its Services are enough
- One cloud with managed discovery
- A handful of services behind load balancers
- You only need a lock or a small store
- You must ship it inside a competing product
Neighbours
| Option | Same | Different | Choose it when |
|---|---|---|---|
| Kubernetes Services | Names for healthy copies | Inside one cluster, nothing more to run | All in one cluster |
| AWS Cloud Map | Registry with DNS and API | Managed, AWS only, no locks, no mesh | All on AWS |
| etcd | Raft, watches, leases | A store only: no DNS, no checks | You build the rest |
| ZooKeeper | Coordination, locks | Ordered tree of nodes, no DNS | Software that already needs it |
| Istio | Mesh with mTLS and rules | Centred on Kubernetes, uses its registry | Rich traffic rules in clusters |
Summary
The whole topic in one minute.
Consul servers agree on the catalog with Raft. Client agents register services, run checks next to the program, and use gossip to notice dead machines. Callers use DNS or HTTP, and long-lived watchers use blocking queries. A mesh of Envoy proxies can add encryption and permission by service name.
Choose it for many services on mixed platforms with people to run it. Inside one Kubernetes cluster or one cloud, the built-in discovery is usually enough. Check the licence: it is source-available under BUSL 1.1 and no longer open source.
- Three or five servers agree with Raft; clients register, check and gossip.
- The local agent is the authority; anti-entropy repairs the catalog.
- DNS answers are uncached and may be stale; choose consistent reads for locks.
- Locks are advisory: add a fencing number.
- Intentions decide who may call whom, and live in the proxies.
- ACLs and agent TLS are off until you turn them on. The licence is BUSL 1.1.