Eureka vs Consul: Service Discovery Comparison
Fast recall
Quick revision
Core answer
Whether you understand the CAP theorem trade-offs in service discovery, what Eureka's self-preservation mode means, and when the operational complexity of Consul pays off
Assuming Consul is always better because it's CP — for service discovery in a single-datacenter Spring-only environment, Eureka's simplicity and native Spring integration are often the right trade-off
Discuss Eureka's self-preservation mode (holds stale registrations during network partitions to avoid mass de-registration), Consul's Raft quorum requirements (need majority), and the rise of Kubernetes-native discovery (CoreDNS + Services) that makes both less relevant in cloud-native deployments
Interview-ready guide
Interview answer
Both solve service discovery, but their failure modes are opposite. Eureka is AP — during a network partition, it keeps serving stale registry data. Consul is CP — during a partition, the minority side can't register or discover services.
Eureka's self-preservation mode stops evicting instances during mass heartbeat failures — assumes network issue, not instance failure. You might route to dead instances, but the registry stays available.
Consul uses Raft consensus — a quorum must agree before registry changes. The registry is always accurate but may be temporarily unavailable.
Health checks differ: Eureka relies on client heartbeats (passive). Consul actively probes with HTTP/TCP checks — catches processes that are running but not serving.
Consul also provides a KV store, ACLs, and multi-datacenter federation. Eureka is Java-only and Netflix OSS with reduced investment.
In practice, Eureka fits Spring-only shops. Consul fits polyglot architectures and when you need the KV store and health checking.
Eureka vs Consul: Service Discovery Comparison
Direct Answer
Eureka is a Spring/Netflix-native AP service registry (availability over consistency) built specifically for service discovery. Consul is a broader infrastructure tool (CP with Raft consensus) providing service discovery, health checks, KV store, and service mesh — more operationally complex but better suited for multi-cloud or multi-language environments.
Code Example
The configuration surface for each registry highlights the philosophical difference.
Eureka — JVM-native, annotation-driven:
<!-- pom.xml: client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
@SpringBootApplication
@EnableDiscoveryClient // Eureka auto-registers on startup
public class OrderServiceApp {
public static void main(String[] args) { SpringApplication.run(OrderServiceApp.class, args); }
}
# application.yml (Eureka client)
spring:
application.name: order-service
eureka:
client:
service-url.defaultZone: http://eureka-server:8761/eureka/
registry-fetch-interval-seconds: 30
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 30 # heartbeat every 30s
lease-expiration-duration-in-seconds: 90 # evict after 90s silence
metadata-map:
version: '2.3.1'
zone: us-east-1a
Eureka server (minimal):
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApp {
public static void main(String[] args) { SpringApplication.run(EurekaServerApp.class, args); }
}
# eureka-server application.yml
server.port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
server:
enable-self-preservation: true # classic AP behaviour
renewal-percent-threshold: 0.85
Consul — same service, HTTP API + active probing:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
# application.yml (Consul client)
spring:
application.name: order-service
cloud:
consul:
host: consul.internal
port: 8500
discovery:
register: true
prefer-ip-address: true
health-check-path: /actuator/health # Consul actively probes this
health-check-interval: 10s
health-check-timeout: 3s
health-check-critical-timeout: 30s # deregister if critical this long
tags:
- version=2.3.1
- zone=us-east-1a
- secure=false
instance-zone: us-east-1a
Raw Consul service definition (language-agnostic — a Go or Python service would register the same way):
{
"service": {
"name": "order-service",
"address": "10.0.1.42",
"port": 8080,
"tags": ["version=2.3.1", "zone=us-east-1a"],
"checks": [
{
"http": "http://10.0.1.42:8080/actuator/health",
"interval": "10s",
"timeout": "3s"
},
{
"tcp": "10.0.1.42:8080",
"interval": "30s"
}
]
}
}
The telling differences:
-
Registration mode — Eureka requires
@EnableDiscoveryClientand classpath dependency (JVM-specific). Consul uses an HTTP API that any language can call — a Go service ships withconsul.Client.Agent().ServiceRegister(...)identical in spirit to the YAML above. -
Health checks — Eureka uses passive lease renewal (
lease-renewal-interval-in-seconds: 30). A broken service that still heartbeats appears healthy. Consul actively probeshealth-check-path; a service returning 503 on/actuator/healthis deregistered withinhealth-check-interval + critical-timeout. -
Multi-kind checks — Consul supports multiple simultaneous checks per service (HTTP + TCP above). A single failed HTTP check marks the service unhealthy even if TCP is up. Eureka's single-signal heartbeat can't express this.
-
CAP signal in config —
enable-self-preservation: truein Eureka is the AP tell; Consul's requirement of a server quorum (configured inconsul-server.hcl, not shown) is the CP tell.
Consul also gives you the KV store for free:
consul kv put features/new-checkout-ui true
consul kv get features/new-checkout-ui
Spring services read via spring-cloud-starter-consul-config. Eureka has no KV equivalent.
Common Mistakes & Pitfalls
Assuming Consul is always better because it's CP — for service discovery in a single-datacenter Spring-only environment, Eureka's simplicity and native Spring integration are often the right trade-off
Check your understanding
Answer these without looking back at the article.
- What is Eureka's self-preservation mode and why was it introduced?
- How does Spring Cloud LoadBalancer use the service registry to route requests?
- In a Kubernetes environment, would you still use Eureka or Consul? Why or why not?
Related interview prep categories
2Want a guided curriculum order?
These modules are also sequenced in our flagship backend interview track — open it when you prefer an ordered path instead of browsing by topic.