7. Genesis of an entertaining (?) talk about microservices
We’ll explore how to architect and operate microservices following the adventures of three monkeys that
need to collaborate to get rid of nasty bugs
8. The Sucker
Meet the first micromonkey: the sucker. He will happily groom anyone who requests it.
The
Sucker™
9. The Cheater
This micromonkey is fundamentally a bastard. He asks the help of others when in need, but always
refuse to groom anyone back. Not. Nice.
The Cheater™
10. The Grudger
Our last micromonkey is there to counter antisocial behaviors: if someone refuses to groom when he
asks, he will hold a grudge and refuse to groom the cheater afterwards.
The Grudger™
11. Life, a tick at a time
Our micromonkeys live a quantised life. The Simulator takes care of notifying the monkeys when it’s time
to go one more clock tick ahead.
The Simulator™
15. Immutable deployment units
It’s my app in a box, babe!
Containers give you a unified distribution model across technologies and an efficient way of using your
system resources. Together with stateleness, they’re much more easy to hot-deploy than WAR files!
command = ["java", "-Dmonkey=grudger",
"-Dmonkey-id=1",
"-Dmonkey-port=8081",
"-Dmonkey-consul-endpoint=http://192.168.59.103:8500",
"-jar", "grudger.jar"]
single app
boundary$ lein uberjar
$ docker build
16. Beware of hidden complexity
Extended application domain
When you distribute your app as a Docker container, you’re also distributing (a part of) the OS, and as
such you’re responsible for it.
distro selection
security guarantees
persistent storage
init system
kernel panicslinked containers
17. (def stem-micromonkey
["/"
{"" api-index
"clock" {:put process-clock
:get show-clock}
"bugs" {:put add-bugs
:delete remove-bugs}
"status" status
"groom" {:post will-groom}
"reborn" {:post resuscitate}
"config" show-config}])
REST + (a)sync + P2P
REST + HTTPKit + core.async
The micromonkeys expose a tiny REST APIs using bidi and talk to each other using synchronous
request/response patterns, while the simulator use core.async to interact with them.
minimal API
fast responses
per-node transaction
18. States catch up: CAP
Convergent replicated data type (CvRDT)
The micromonkeys only shared state is a counter, treated as monotonically increasing. When the monkey
is dead it simulates a partition. As the clock value is sent along the tick request, state is trivially restored.
4242
42
36
43 44 45
36 36 45
25. Service discovery
it’s me!
it’s me!
it’s me!
Service registration
At bootstrap, each micromonkey registers into Consul, exposing information like their URL, esposed TCP
port, what service category (-> monkey type) they are and what health check system to use.
26. Service discovery
Are there alive
monkeys?
Are there alive
monkeys?
Multi protocol
Consul accepts both HTTP and DNS queries to expose information regarding registered services.
27. Much more!
Full package
Consul comes with a variety of other extra features that make automation a pleasure. More info and full
documentation at http://consul.io
watches
kv store
distributed
cross datacenter
sweet!
29. Fault tolerance
Circuit breakers FTW
When things go sideways and failures propagate throughout your system, then being distributed won’t
improve your resilience.
(decommand ask-grooming
"Asks a monkey to groom us"
[monkey]
(let [res-chan (rest/ask-grooming monkey)]
(go (let [[response ch] (alts! response-chan
(timeout (config/response-timeout)))]
(if (= response-chan ch)
(process-response ch)
(throw (MonkeyTimeoutException. monkey)))))))
33. Inspired by
Among the other million links
The whole Internet is talking about microservices, but these two offered a similar pattern for a full
microservices deployment which inspired the design of the Micromonkeys.