35
Grudging monkeys and microservices @ by Carlo Sciolla

Grudging monkeys and microservices

Embed Size (px)

Citation preview

Grudging monkeysand microservices

@ by Carlo Sciolla

whoami since 2010!

So... µservices, huh?

Ask the architect

“ there is nothing new under the sun-- “Uncle Bob” Martin on Microservices

But then

- smaller, isolated codebases- stateless & immutable- no distributed transactions- polyglot trojan horse

Meet the micromonkeys

Genesis of an entertaining (?) talk about microservicesWe’ll explore how to architect and operate microservices following the adventures of three monkeys that need to collaborate to get rid of nasty bugs

The SuckerMeet the first micromonkey: the sucker. He will happily groom anyone who requests it.

The Sucker™

The CheaterThis 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™

The GrudgerOur 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™

Life, a tick at a timeOur 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™

DEMO TIME!(wish me luck)

The macro picture

How micro is micro?single appboundary

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 appboundary$ lein uberjar

$ docker build

Beware of hidden complexity

Extended application domainWhen 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

(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.asyncThe 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 APIfast responsesper-node transaction

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

4236

43 44 45

36 36 45

Terraform

Immutable infrastructure

v1 v2

v1

$ terraform plan$ terraform apply$ git commit

Go CD

Automate everything

Continuous Delivery

docker build

automatedinfrastructure

Consul

Service discoveryit’s me!

it’s me!

it’s me!

Service registrationAt 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.

Service discovery

Are there alive monkeys?

Are there alive monkeys?

Multi protocolConsul accepts both HTTP and DNS queries to expose information regarding registered services.

Much more!

Full packageConsul 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

distributedcross datacenter

sweet!

What to explore next

Fault tolerance

Circuit breakers FTWWhen 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)))))))

Auto scaling and scheduling

Persistent storage with Flocker

Monitoring (ELK, New Relic..)

Inspired by

Among the other million linksThe 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.

Questions?

Thank you!

Carlo Sciolla Chief Technology Officer

http://skuro.tkhttp://sytac.io@skuro