SlideShare a Scribd company logo
Service Discovery like a Pro
Eran Harel
@eran_ha
● Motivation
● Consul Overview
● Consul Architecture
● API
● Alternatives
● Discovery and Client Side LB Demo
Do we have a problem at all?
my.target.service.url=http://host:port/contextBase/...
memcached.cluster=mem1:11211,mem1:11311,mem2:11211,mem2:111311
db.host=mysql:3304
kafka.brokers=kafka1:9092,kafka2:9092,kafka3:9092
Hard Coded Topology...
● What do we do if the nodes are dynamically allocated (e.g.
when using a scheduler a-la Mesos)?
● What do we do when the topology changes?
● What do we do if nodes become unhealthy?
● How can we scale (up/down) our clusters?
● What happens if the port is dynamic?
Why is Hard Coded Topology a problem?
The Traditional Approaches
● HTTP Load Balancers (e.g. HAProxy)
● TCP Keepalive
● VIP
● etc...
What is Consul?
Service discovery and configuration
made easy. Distributed, highly
available, and datacenter-aware.
● Developed @ Hashicorp
● Open source - https://github.com/hashicorp/consul
● Written in Go
● Current version 0.7.2
● https://consul.io/
● Service Discovery
● Scalable Failure Detection (Distributed Health Checks)
● K/V Store
● Load Balancing
● Multi Datacenter
● consul-template (external project)
Features
Basic Architecture
Consul APIs
DNS API
DNS API
$ host memcached.service.consul
memcached.service.consul has address 10.xx.xx.01
memcached.service.consul has address 10.xx.xx.02
memcached.service.consul has address 10.xx.xx.03
$
$ host test.memcached.service.consul
memcached.service.consul has address 10.xx.xx.51
memcached.service.consul has address 10.xx.xx.52
$
$ host prod.memcached-legacy.service.dc2.consul
memcached.service.consul has address 10.yy.xx.01
memcached.service.consul has address 10.yy.xx.02
REST API
● http://localhost:8500/v1/agent/service/register
● http://localhost:8500/v1/agent/service/deregister/<MyService>
● http://localhost:8500/v1/catalog/services/service/<MyService>
● http://localhost:8500/v1/catalog/nodes
● http://localhost:8500/v1/health/service/<MyService>
● Certain endpoints support a feature called a "blocking query." A blocking query is
used to wait for a potential change using long polling.
Consul CLI
$ consul
usage: consul [--version] [--help] <command> [<args>]
Available commands are:
agent Runs a Consul agent
configtest Validate config file
event Fire a new event
exec Executes a command on Consul nodes
force-leave Forces a member of the cluster to enter the "left" state
info Provides debugging information for operators
join Tell Consul agent to join cluster
keygen Generates a new encryption key
keyring Manages gossip layer encryption keys
leave Gracefully leaves the Consul cluster and shuts down
lock Execute a command holding a lock
maint Controls node or service maintenance mode
members Lists the members of a Consul cluster
monitor Stream logs from a Consul agent
reload Triggers the agent to reload configuration files
rtt Estimates network round trip time between nodes
version Prints the Consul version
watch Watch for changes in Consul
Consul CLI (cont)
$ consul maint -service Hello0 -enable
Service maintenance is now enabled for "Hello0"
On the server log:
2015/12/09 21:51:13 [INFO] agent: Service "Hello0" entered maintenance mode
2015/12/09 21:51:13 [INFO] agent: Synced check '_service_maintenance:Hello0'
What are the alternatives?
● ZooKeeper, doozerd, etcd
● Chef, Puppet, etc
● Nagios, Sensu
● SkyDNS
● SmartStack
● Serf
Implementing Service Discovery
How do we implement discovery and client side LB?
Each module registers itself to the local consul agent upon startup, and provides
enough metadata to allow filtering
http://localhost:8500/v1/register
{
"ID": "Hello0",
"Name": "Hello",
"Port": 8080,
"Tags": [
"instance0",
"production",
"httpPort-8080",
"contextPath-/api",
],
"Check": {
"HTTP": "http://localhost:8080/api/hello/instance",
"Interval": "1s",
"Timeout”: "1s"
}
}
How do we implement discovery and client side LB?
The local consul agent calls the provided health check(s) and verifies the instances are
healthy.
Don’t forget to add proper timeouts!
curl --fail --max-time 1 “http://localhost:8080/api/hello/instance”
How do we implement discovery and client side LB?
Clients perform long polling queries to the health API, maintain a list of healthy
instances, and build target URLs.
At Outbrain we use the ConsulBasedTargetProvider with HealthTargetsList
to achieve this.
http://localhost:8500/v1/health/service/Hello?passing=true&tag=production&stale=true&
index={index}&wait=30s
X-Consul-Index=4245721
How do we implement discovery and client side LB?
Upon client request, we select a target based on some strategy (e.g. round-robin).
How do we implement discovery and client side LB?
Clients need to implement resilience logic such as retries, timeouts, circuit-breakers,
etc
final HelloService helloService = new ClientBuilder<>(HelloService.class).
setProtocol(ContentType.JSON).
setConnectionTimeout(100).
setRequestTimeout(100).
setRetries(3).
setTargetProvider(new ConsulBasedTargetProvider(healthyTargetsList, "/hello", null)).
build();
Discovery and Client Side LB Demo
Hello2
Hello1
http://localhost:8500/v1/register
{
"ID": "Hello0",
"Name": "Hello",
"Port": 8080,
"Tags": [
"instance0",
"production",
"httpPort-8080",
"contextPath-/api",
],
"Check": {
"HTTP": "http://localhost:8080/api/hello/instance",
"Interval": "1s",
"Timeout”: "1s"
}
}
http://localhost:8500/v1/health/service/Hello
?passing=true&tag=production&stale=true
&index={index}&wait=30s
Demo Preview
Hello0 :8080
:8081
:8082
Register
Call service
References & Links
● Consul Docs - https://consul.io/docs/index.html
● Example Source Code -
https://github.com/outbrain/ob1k/tree/master/ob1k-example/src/main/java/com/ou
tbrain/ob1k/example/hello
We are recruiting...
http://www.outbrain.com/about/careers

More Related Content

PDF
MessagePack Rakuten Technology Conference 2010
PDF
Workshop Consul .- Service Discovery & Failure Detection
PDF
Consul presentation
PDF
OB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
PPTX
Ob1k presentation at Java.IL
PPTX
PDF
From nothing to Prometheus : one year after
PDF
Fluentd - CNCF Paris
MessagePack Rakuten Technology Conference 2010
Workshop Consul .- Service Discovery & Failure Detection
Consul presentation
OB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
Ob1k presentation at Java.IL
From nothing to Prometheus : one year after
Fluentd - CNCF Paris

What's hot (20)

PDF
Communication in Python and the C10k problem
PDF
Solving some of the scalability problems at booking.com
PDF
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
PPTX
Debugging varnish
PDF
(Re)discover your AEM
PPTX
Implement server push in flask framework
ODP
Lucio Grenzi - Building serverless applications on the Apache OpenWhisk platf...
PDF
How to stay sane during your Vagrant journey
PDF
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
PDF
OCP with super tengen toppa
PDF
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
PDF
PostgreSQL High-Availability and Geographic Locality using consul
PDF
What is new in Go 1.8
PPTX
Who Broke My Crypto
PPTX
Ruby C10K: High Performance Networking - RubyKaigi '09
PDF
VCL template abstraction model and automated deployments to Fastly
PDF
vienna.js - Automatic testing of (RESTful) API documentation
PDF
Service discovery and puppet
PDF
Building GUI App with Electron and Lisp
PDF
Altitude NY 2018: Programming the edge workshop
Communication in Python and the C10k problem
Solving some of the scalability problems at booking.com
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
Debugging varnish
(Re)discover your AEM
Implement server push in flask framework
Lucio Grenzi - Building serverless applications on the Apache OpenWhisk platf...
How to stay sane during your Vagrant journey
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
OCP with super tengen toppa
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
PostgreSQL High-Availability and Geographic Locality using consul
What is new in Go 1.8
Who Broke My Crypto
Ruby C10K: High Performance Networking - RubyKaigi '09
VCL template abstraction model and automated deployments to Fastly
vienna.js - Automatic testing of (RESTful) API documentation
Service discovery and puppet
Building GUI App with Electron and Lisp
Altitude NY 2018: Programming the edge workshop
Ad

Similar to Service discovery like a pro (presented at reversimX) (20)

PPTX
Service Discovery Like a Pro
PDF
Service discovery in a microservice architecture using consul
PPTX
Service Discovery with Consul - Arunvel Arunachalam
PDF
HashiStack. To the cloud and beyond...
PDF
Introduction to Consul
PDF
Consul: Microservice Enabling Microservices and Reactive Programming
PDF
Soa with consul
PPTX
Intro to Consul
PDF
Consul First Steps
PDF
Consul: Service Mesh for Microservices
PPTX
Discover/Register Everything in consul
PDF
Getting Started with Consul
PDF
Smart networking with service meshes
PPTX
Introduction to service discovery and self-organizing cluster orchestration. ...
PDF
Comparing ZooKeeper and Consul
PDF
Consul - service discovery and others
PDF
Consul tutorial
PPTX
Service Discovery using etcd, Consul and Kubernetes
PDF
PuppetConf 2016: Service Discovery and Puppet – Marc Cluet, Ukon Cherry
PDF
20190727 HashiCorp Consul Workshop: 管管你們家 config 啦
Service Discovery Like a Pro
Service discovery in a microservice architecture using consul
Service Discovery with Consul - Arunvel Arunachalam
HashiStack. To the cloud and beyond...
Introduction to Consul
Consul: Microservice Enabling Microservices and Reactive Programming
Soa with consul
Intro to Consul
Consul First Steps
Consul: Service Mesh for Microservices
Discover/Register Everything in consul
Getting Started with Consul
Smart networking with service meshes
Introduction to service discovery and self-organizing cluster orchestration. ...
Comparing ZooKeeper and Consul
Consul - service discovery and others
Consul tutorial
Service Discovery using etcd, Consul and Kubernetes
PuppetConf 2016: Service Discovery and Puppet – Marc Cluet, Ukon Cherry
20190727 HashiCorp Consul Workshop: 管管你們家 config 啦
Ad

Recently uploaded (20)

PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
AI in Product Development-omnex systems
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
System and Network Administration Chapter 2
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Introduction to Artificial Intelligence
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Digital Strategies for Manufacturing Companies
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
System and Network Administraation Chapter 3
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
AI in Product Development-omnex systems
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
ManageIQ - Sprint 268 Review - Slide Deck
System and Network Administration Chapter 2
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Wondershare Filmora 15 Crack With Activation Key [2025
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Operating system designcfffgfgggggggvggggggggg
Introduction to Artificial Intelligence
Odoo Companies in India – Driving Business Transformation.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
CHAPTER 2 - PM Management and IT Context
Digital Strategies for Manufacturing Companies
Adobe Illustrator 28.6 Crack My Vision of Vector Design
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
System and Network Administraation Chapter 3

Service discovery like a pro (presented at reversimX)

  • 1. Service Discovery like a Pro Eran Harel @eran_ha
  • 2. ● Motivation ● Consul Overview ● Consul Architecture ● API ● Alternatives ● Discovery and Client Side LB Demo
  • 3. Do we have a problem at all?
  • 5. ● What do we do if the nodes are dynamically allocated (e.g. when using a scheduler a-la Mesos)? ● What do we do when the topology changes? ● What do we do if nodes become unhealthy? ● How can we scale (up/down) our clusters? ● What happens if the port is dynamic? Why is Hard Coded Topology a problem?
  • 7. ● HTTP Load Balancers (e.g. HAProxy) ● TCP Keepalive ● VIP ● etc...
  • 9. Service discovery and configuration made easy. Distributed, highly available, and datacenter-aware.
  • 10. ● Developed @ Hashicorp ● Open source - https://github.com/hashicorp/consul ● Written in Go ● Current version 0.7.2 ● https://consul.io/
  • 11. ● Service Discovery ● Scalable Failure Detection (Distributed Health Checks) ● K/V Store ● Load Balancing ● Multi Datacenter ● consul-template (external project) Features
  • 15. DNS API $ host memcached.service.consul memcached.service.consul has address 10.xx.xx.01 memcached.service.consul has address 10.xx.xx.02 memcached.service.consul has address 10.xx.xx.03 $ $ host test.memcached.service.consul memcached.service.consul has address 10.xx.xx.51 memcached.service.consul has address 10.xx.xx.52 $ $ host prod.memcached-legacy.service.dc2.consul memcached.service.consul has address 10.yy.xx.01 memcached.service.consul has address 10.yy.xx.02
  • 16. REST API ● http://localhost:8500/v1/agent/service/register ● http://localhost:8500/v1/agent/service/deregister/<MyService> ● http://localhost:8500/v1/catalog/services/service/<MyService> ● http://localhost:8500/v1/catalog/nodes ● http://localhost:8500/v1/health/service/<MyService> ● Certain endpoints support a feature called a "blocking query." A blocking query is used to wait for a potential change using long polling.
  • 17. Consul CLI $ consul usage: consul [--version] [--help] <command> [<args>] Available commands are: agent Runs a Consul agent configtest Validate config file event Fire a new event exec Executes a command on Consul nodes force-leave Forces a member of the cluster to enter the "left" state info Provides debugging information for operators join Tell Consul agent to join cluster keygen Generates a new encryption key keyring Manages gossip layer encryption keys leave Gracefully leaves the Consul cluster and shuts down lock Execute a command holding a lock maint Controls node or service maintenance mode members Lists the members of a Consul cluster monitor Stream logs from a Consul agent reload Triggers the agent to reload configuration files rtt Estimates network round trip time between nodes version Prints the Consul version watch Watch for changes in Consul
  • 18. Consul CLI (cont) $ consul maint -service Hello0 -enable Service maintenance is now enabled for "Hello0" On the server log: 2015/12/09 21:51:13 [INFO] agent: Service "Hello0" entered maintenance mode 2015/12/09 21:51:13 [INFO] agent: Synced check '_service_maintenance:Hello0'
  • 19. What are the alternatives? ● ZooKeeper, doozerd, etcd ● Chef, Puppet, etc ● Nagios, Sensu ● SkyDNS ● SmartStack ● Serf
  • 21. How do we implement discovery and client side LB? Each module registers itself to the local consul agent upon startup, and provides enough metadata to allow filtering http://localhost:8500/v1/register { "ID": "Hello0", "Name": "Hello", "Port": 8080, "Tags": [ "instance0", "production", "httpPort-8080", "contextPath-/api", ], "Check": { "HTTP": "http://localhost:8080/api/hello/instance", "Interval": "1s", "Timeout”: "1s" } }
  • 22. How do we implement discovery and client side LB? The local consul agent calls the provided health check(s) and verifies the instances are healthy. Don’t forget to add proper timeouts! curl --fail --max-time 1 “http://localhost:8080/api/hello/instance”
  • 23. How do we implement discovery and client side LB? Clients perform long polling queries to the health API, maintain a list of healthy instances, and build target URLs. At Outbrain we use the ConsulBasedTargetProvider with HealthTargetsList to achieve this. http://localhost:8500/v1/health/service/Hello?passing=true&tag=production&stale=true& index={index}&wait=30s X-Consul-Index=4245721
  • 24. How do we implement discovery and client side LB? Upon client request, we select a target based on some strategy (e.g. round-robin).
  • 25. How do we implement discovery and client side LB? Clients need to implement resilience logic such as retries, timeouts, circuit-breakers, etc final HelloService helloService = new ClientBuilder<>(HelloService.class). setProtocol(ContentType.JSON). setConnectionTimeout(100). setRequestTimeout(100). setRetries(3). setTargetProvider(new ConsulBasedTargetProvider(healthyTargetsList, "/hello", null)). build();
  • 26. Discovery and Client Side LB Demo
  • 27. Hello2 Hello1 http://localhost:8500/v1/register { "ID": "Hello0", "Name": "Hello", "Port": 8080, "Tags": [ "instance0", "production", "httpPort-8080", "contextPath-/api", ], "Check": { "HTTP": "http://localhost:8080/api/hello/instance", "Interval": "1s", "Timeout”: "1s" } } http://localhost:8500/v1/health/service/Hello ?passing=true&tag=production&stale=true &index={index}&wait=30s Demo Preview Hello0 :8080 :8081 :8082 Register Call service
  • 28. References & Links ● Consul Docs - https://consul.io/docs/index.html ● Example Source Code - https://github.com/outbrain/ob1k/tree/master/ob1k-example/src/main/java/com/ou tbrain/ob1k/example/hello