Service Discovery
with
@lukeb0nd
luke@yld.io
London Microservices User Group
April 2015
@lukeb0nd
luke@yld.io
London μServices April 2015
Who am I?
- Server developer at YLD.io
- Software engineering consultency
- We do microservices
- Node.js and Docker
- We're hiring!
- Building "paz": http://paz.sh
- Built British Gas Connected Boilers backend (Node.js Docker microservices)
@lukeb0nd
luke@yld.io
London μServices April 2015
Paz
Docker PaaS (Node.js, CoreOS, Etcd, Fleet)
@lukeb0nd
luke@yld.io
London μServices April 2015
Connected Boilers
British Gas Connected Homes
- Microservices
- Docker
- Node.js
- IoT
- CoreOS, Etcd, Fleet
@lukeb0nd
luke@yld.io
London μServices April 2015
Microservices Bus
@lukeb0nd
luke@yld.io
- What is etcd?
- Raft
- Comparisons
- Demo
- Using etcd for service discovery
London μServices April 2015
@lukeb0nd
luke@yld.io
"A highly available key value store for shared configuration and service discovery"
London μServices April 2015
@lukeb0nd
luke@yld.io
Simple: curl'able user facing API (HTTP+JSON)
London μServices April 2015
@lukeb0nd
luke@yld.io
Secure: optional SSL client cert authentication
London μServices April 2015
@lukeb0nd
luke@yld.io
Fast: benchmarked 1000s of writes/s per instance
London μServices April 2015
@lukeb0nd
luke@yld.io
Reliable: properly distributed using Raft
London μServices April 2015
@lukeb0nd
luke@yld.io
London μServices April 2015
@lukeb0nd
luke@yld.io
London μServices April 2015
The Raft Algorithm
@lukeb0nd
luke@yld.io
London μServices April 2015
Consensus
Distributed "agreeing on stuff"
@lukeb0nd
luke@yld.io
London μServices April 2015
@lukeb0nd
luke@yld.io
London μServices April 2015
Comparisons
etcd
- Written in Go
- Raft algorithm
- Established, becoming well-understood
- HTTP REST interface
- Clients are just convenience wrappers around a REST interface
- Will remain up during a split
ZooKeeper
- Written in Java
- Zab algorithm
- Well-understood & proven
- Custom protocol over TCP
- Hopefully there is a client for your language
- Will shut-down smaller partition in case of a split
@lukeb0nd
luke@yld.io
London μServices April 2015
etcd
- Written in Go
- Raft algorithm
- HTTP REST interface
- Written by CoreOS
- Has been around for a while now
- A building-block for a service discovery system
Consul
- Written in Go
- Raft algorithm
- HTTP REST interface
- Written by Hashicorp (Vagrant, Terraform, etc.)
- Newer and less proven
- A fully-featured service discovery system
@lukeb0nd
luke@yld.io
London μServices April 2015
@lukeb0nd
luke@yld.io
London μServices April 2015
etcdctl demo
@lukeb0nd
luke@yld.io
London μServices April 2015
Service Discovery
@lukeb0nd
luke@yld.io
London μServices April 2015
etcd is not a service discovery solution
@lukeb0nd
luke@yld.io
London μServices April 2015
What might an etcd-based service discovery solution look like?
@lukeb0nd
luke@yld.io
London μServices April 2015
- When apps start, write announce info into Etcd
- If one app needs to discover another:
- Lookup Etcd
- Pass value as environment variable to app
@lukeb0nd
luke@yld.io
London μServices April 2015
How to Improve on this?
- A talk in itself!
- Need something dynamic
- Let's look at some options
@lukeb0nd
luke@yld.io
London μServices April 2015
DNS
- Propagation slow
- Port 80 only unless you use SRV records
- Don't want to enforce that on your apps
- IMHO unsatisfactory
@lukeb0nd
luke@yld.io
London μServices April 2015
Ambassadors
- A service discovery pattern
- If A wants to talk to B, let C be a dynamically configured interloper
- When B's address changes C knows about it and can route to the "new" B
- Naive implementation limited, doing it well takes you into... ->
@lukeb0nd
luke@yld.io
London μServices April 2015
HAProxy/nginx/iptables
- Can be configured dynamically
- Using Etcd and Confd
- Rewrite config on Etcd change, signal server to reload config
- HAProxy can do this without dropping connections, even if services die
- Powerful, but dynamic config can be messy & difficult to maintain
@lukeb0nd
luke@yld.io
London μServices April 2015
Use a Docker PaaS
- Kubernetes
- Mesos
- Paz
- Deis
Most do something like the previous slide.
All use Etcd to drive the dynamic config.
@lukeb0nd
luke@yld.io
London μServices April 2015
Wrap-up
- The primitives exist
- Etcd, HAProxy, etc.
- Either build your SD solution on top of those
- Or go off-the-shelf
- Some sort of highly-available, dynamic ambassador pattern is the only solid solution right now
- This whole area is immature (aka exciting times)
@lukeb0nd
luke@yld.io
London μServices April 2015
Questions?
service-discovery-etcd
By Luke Bond
service-discovery-etcd
- 2,107