service discovery or why each micro service should believe it's the only one in the world

35
Service Discovery or Why each microservice should believe it's the only one in the world. Richard Rodger @rjrodger

Upload: icemobile

Post on 15-Jan-2017

516 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Service Discovery or Why each micro service should believe it's the only one in the world

Service Discovery or

Why each microservice should believe it's the only one in the world.

Richard Rodger @rjrodger

Page 2: Service Discovery or Why each micro service should believe it's the only one in the world
Page 3: Service Discovery or Why each micro service should believe it's the only one in the world
Page 4: Service Discovery or Why each micro service should believe it's the only one in the world

What are microservices?

๏ Small independent processes; ๏ Communicating via messages; ๏ A powerful component model.

Page 5: Service Discovery or Why each micro service should believe it's the only one in the world

Why use microservices?

๏ Avoid technical debt; ๏ Get continuous delivery; ๏ Build fast.

Page 6: Service Discovery or Why each micro service should believe it's the only one in the world

What are the trade-offs?

๏ Deployment is more complex; ๏ Weird programming model; ๏ Services have to find each other;

Page 7: Service Discovery or Why each micro service should believe it's the only one in the world
Page 8: Service Discovery or Why each micro service should believe it's the only one in the world
Page 9: Service Discovery or Why each micro service should believe it's the only one in the world
Page 10: Service Discovery or Why each micro service should believe it's the only one in the world

Configuration Files

๏ Hard code all the locations; ๏ Automate update and reloads; ๏ Surprisingly workable; ๏ But gets messy fast!

Page 11: Service Discovery or Why each micro service should believe it's the only one in the world

Intelligent Load Balancing

๏ The load balancer knows where services are; ๏ Services have to register in some way; ๏ Load balancers are yet more things to manage; ๏ URL paths are still identifiers! ๏ Examples: Netflix Eureka, nginx, HAProxy

Page 12: Service Discovery or Why each micro service should believe it's the only one in the world

Service Registries

๏ Services lookup locations; ๏ Registries can provide health checks; ๏ Registries themselves need to be distributed; ๏ Service A still knows about Service B! ๏ Examples: consul, etcd, zookeeper

Page 13: Service Discovery or Why each micro service should believe it's the only one in the world

DNS

๏ Hide services behind domain names; ๏ We know DNS can scale; ๏ More management work; ๏ Service A still knows about Service B! ๏ Examples: Mesos, Weave, SkyDNS

Page 14: Service Discovery or Why each micro service should believe it's the only one in the world

Message Bus

๏ Hide services behind topic names; ๏ Nice for publish/subscribe models! ๏ You have to manage the bus; ๏ Rapids, rivers and pools; ๏ Topics are weak identifiers - better! ๏ Examples: Kafka, Rabbitmq, Redis

Page 15: Service Discovery or Why each micro service should believe it's the only one in the world
Page 16: Service Discovery or Why each micro service should believe it's the only one in the world

Pattern Matching Service discovery is an anti-pattern. Instead, make messages first-class citizens. Use message data to define patterns, and these patterns define a language! Transport Independence Services should not know about each other, or how to send messages. Services are fully defined by: message patterns that they recognise, and message patterns that they emit.

Page 17: Service Discovery or Why each micro service should believe it's the only one in the world

Blind Messages

๏ Services have zero-knowledge of other services; ๏ Services emit messages into the world; ๏ Services let the world know what they care about;

๏ The underlying infrastructure handles identity; ๏ Works with any of the service discovery methods!

Page 18: Service Discovery or Why each micro service should believe it's the only one in the world

Peer-to-peer

๏ Knowledge of identity can be distributed; ๏ Each service maintains a local view of world,

and updates this view as services come and go; ๏ Mapping from message to destination is not

exposed to developers.

Page 19: Service Discovery or Why each micro service should believe it's the only one in the world

SWIM

๏ "Scalable Weakly-consistent Infection-style Process Group Membership Protocol" ๏ https://www.cs.cornell.edu/~asdas/research/dsn02-swim.pdf

๏ Designed for large scale (used by Uber); ๏ Basic idea:

๏ each service pings a random subset of other services, different each time

๏ the pings establish health and disseminate membership information

Page 20: Service Discovery or Why each micro service should believe it's the only one in the world
Page 21: Service Discovery or Why each micro service should believe it's the only one in the world
Page 22: Service Discovery or Why each micro service should believe it's the only one in the world
Page 23: Service Discovery or Why each micro service should believe it's the only one in the world

// a search message { "role": "search", // a namespace "cmd": "search", // this is a command "query": "ldap", // some data } !// the pattern to match role:search,cmd:search

Page 24: Service Discovery or Why each micro service should believe it's the only one in the world

// some nodezoo message patterns !role:search,cmd:search // do a search role:search,cmd:insert // insert into index role:info,cmd:get // get module info role:npm,cmd:get // get npm data role:npm,info:change // module changed! role:info,req:part // need module info role:info,res:part // here's module info !!!

Page 25: Service Discovery or Why each micro service should believe it's the only one in the world

role:search,cmd:search

role:info,cmd:get

synchronous request/response

Page 26: Service Discovery or Why each micro service should believe it's the only one in the world

role:npm,info:change

asynchronous "winner-take-all" (actor)

Page 27: Service Discovery or Why each micro service should believe it's the only one in the world

role:info,req:part

asynchronous "fire-and-forget" (publish/subscribe)

role:info,res:part

Page 28: Service Discovery or Why each micro service should believe it's the only one in the world

asynchronous "fire-and-forget" (publish/subscribe)

synchronous request/response

asynchronous "winner-take-all" (actor)

synchronous "sidewinder" (side effects!)

synchronous/ asynchronous

consumed/ observed

Page 29: Service Discovery or Why each micro service should believe it's the only one in the world

// nodezoo-web IN: none OUT: role:search,cmd:search // sync role:info,cmd:get // sync

// nodezoo-search IN: role:search,cmd:search // sync role:search,cmd:insert // async OUT: none

service specification

Page 30: Service Discovery or Why each micro service should believe it's the only one in the world

// nodezoo-info IN: role:info,cmd:get // sync role:info,res:part // async OUT: role:info,req:part // async

// nodezoo-npm IN: role:npm,cmd:get // sync role:npm,info:change // async role:info,req:part // async OUT: role:info,res:part // async

service specification

Page 31: Service Discovery or Why each micro service should believe it's the only one in the world

// role:search,cmd:search consumed: nodezoo-web -> nodezoo-search

// role:info,cmd:get consumed: nodezoo-web -> nodezoo-info

// role:npm,info:change observed: nodezoo-update -> nodezoo-npm

service interactions

Page 32: Service Discovery or Why each micro service should believe it's the only one in the world

// role:info,req:part observed: nodezoo-info -> nodezoo-npm nodezoo-info -> nodezoo-github

// role:info,res:part observed: nodezoo-npm -> nodezoo-info nodezoo-github -> nodezoo-info

service interactions

Page 33: Service Discovery or Why each micro service should believe it's the only one in the world

senecajs.org

Page 34: Service Discovery or Why each micro service should believe it's the only one in the world

Code! github.com/rjrodger/nodezoo

Page 35: Service Discovery or Why each micro service should believe it's the only one in the world

Thanks!Richard Rodger

@rjrodger richardrodger.com

senecajs.org github.com/apparatus/fuge