Microservices and Erlang/OTP Christoph Iserlohn
About me Senior Consultant @ innoq MacPorts Team member
Agenda > Microservices > Erlang / OTP > How they fit together
Microservices
Attempt of definition > A system consisting of small, selfcontained services. All running isolated from each other, communicating only over the network.
Monoliths old and busted Old Step Van_MG_3279 by Kool Cats Photgraphy over 3 Million Views. Licensed under CC BY 2.0
Microservices the new hotness Hot Hot Hot" by flattop341. Licensed under CC BY 2.0
VS.
cognitive dimension Pinky & The Brain" by JD Hancock. Licensed under CC BY 2.0
on the service level: more comprehensible "Nasa earth" by NASA ESA - http://www.nasa.gov/. Licensed under Public Domain via Wikimedia Commons - http://commons.wikimedia.org/wiki/file:nasa_earth.jpg#mediaviewer/file:nasa_earth.jpg
on the system level: unable to see the big picture "Infant Stars in Orion" by NASA/JPL-Caltech/D. Barrado y Navascuàs (LAEFF-INTA) - http://www.spitzer.caltech.edu/images/2131-sig07-006-young-stars-emerge-from-orion-s-head. Licensed under Public Domain via Wikimedia Commons - http://commons.wikimedia.org/wiki/file:infant_stars_in_orion.jpg#mediaviewer/file:infant_stars_in_orion.jpg
organisational dimension Model of graphene structure by CORE-MATERIALS. Licensed under CC BY-SA 2.0
organized around business capabilities The Market Economy by Baer Tierkel. Licensed under CC BY 2.0
cross-functional teams Storm Squad by JD Hancock. Licensed under CC BY 2.0
you build it, you run it _DJM7077 by nubigena. Licensed under CC BY-ND 2.0
technological dimension Microchip e microciop by Fabrizio Sciami. Licensed under CC BY-SA 2.0
fault tolerance resilience broken macbook home key by Doctor Rose. Licensed under CC BY-ND 2.0
asynchronous communication Sept 25/10 Old German postbox by Judith Doyle. Licensed under CC BY-ND 2.0
coarse-grained interfaces phone by raindog808. Licensed under CC BY 2.0
sophisticated monitoring "Mission control center" by NASAOriginal uploader was Cjosefy at en.wikipedialater version(s) were uploaded by TheDJ at en.wikipedia. - http://spaceflight.nasa.gov/gallery/images/shuttle/sts-114/html/jsc2005e09159.htmltransferred from en.wikipedia. Licensed under Public Domain via Wikimedia Commons - http://commons.wikimedia.org/wiki/file:mission_control_center.jpg#mediaviewer/file:mission_control_center.jpg
infrastructure automation Tesla Robot Dance by Steve Jurvetson. Licensed under CC BY 2.0
Advantages > fast development cycle > it s easy to scale > flexibility of implementation > easy to get started for new developers > parts of the system can be replaced
Prerequisites > monitoring the whole system > central logging > tracing across service boundaries > automatic deployment > automatic provisioning
Challenges > service boundaries > contracts and governance > testing and refactoring > fallacies of distributed systems > support for a dozen technology stacks
Open questions > how big? > isn t this just SOA?
Summary > it s a promising approach, > but don t start with it mindlessly
Where are we now? "Gartner Hype Cycle" by Jeremykemp at en.wikipedia. Licensed under CC BY-SA 3.0 via Wikimedia Commons http://commons.wikimedia.org/wiki/file:gartner_hype_cycle.svg#mediaviewer/file:gartner_hype_cycle.svg
Erlang / OTP
What is Erlang / OTP? > a general purpose programming language > runtime environment and VM > Open Telecom Platform: libraries, tools and design patterns for building highly concurrent, distributed, fault tolerant systems
fault tolerant to software and hardware errors "BSoD in Windows 8" by Microsoft - Transferred from en.wikipedia to Commons.. Licensed under Public Domain via Wikimedia Commons - http://commons.wikimedia.org/wiki/file:bsod_in_windows_8.png#mediaviewer/file:bsod_in_windows_8.png
distributed systems "BalticServers data center" by Fleshas - I took this photo. Licensed under CC BY-SA 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/file:balticservers_data_center.jpg#mediaviewer/file:balticservers_data_center.jpg
non-stop running - continous operation over years "CEV-ISS" by NASA - http://www.nasa.gov/mission_pages/exploration/spacecraft/cev_hi_res.html. Licensed under Public Domain via Wikimedia Commons - http://commons.wikimedia.org/wiki/file:cev-iss.jpg#mediaviewer/file:cev-iss.jpg
Principles > lightweight concurrency > asynchronous communication > isolation > error handling > simple high-level language > tools not solutions or products
Erlang the language > high-level functional language > prolog inspired syntax > dynamically typed / safe > pattern matching everywhere > recursion > immutable data and variables
-module(factorial).! -export([factorial/1]).!! factorial(n) when N >= 0 -> factorial(n,1).!! factorial(0,acc) -> Acc;! factorial(n,acc) -> factorial(n-1,n*acc).!
Concurrency > millions of processes on one machine > processes are isolated > processes are used for everything: > concurrency > managing state > parallelism > no global data
Message passing > asynchronous > primitives: > fire & forget send > selective receive > more complex interactions can be built on top of these primitives
-module(pingpong). -export([start/1]). start(n) when N > 0 -> Pong = spawn(fun pong/0), ping(n, Pong). ping(0,pong) -> Pong! exit, ok; ping(n, Pong) -> Pong! {self(), ping}, receive pong -> io:format("pid ~p: got pong. ~p pings left~n", [self(), N-1]) end, ping(n - 1, Pong). pong() -> receive {From, ping} -> io:format("pid ~p: got ping from ~p~n", [self(), From]), From! pong, pong(); exit -> ok end.!
Error handling > avoid error checking code everywhere > let it crash > process based: > link - bidirectional > monitor - unidirectional > supervision trees
Supervision trees
Supervision trees
Supervision trees
Supervision trees
Distribution > loosely coupled nodes > mostly transparent > TCP/IP based
OTP > helps creating: > servers > finites state machines > event handler > supervisors > releases and upgrades
Hot code loading > module is unit of code handling > exists in two variants: old and current > controlled take over
Instrumentation > can trace almost everything: process events, send & receive messages, function calls > process introspection: memory, mailbox, links, cur. function... > interactive shell > SNMP based OAM
Summary > everything you need for building highly concurrent, distributed, robust systems > but not well suited for number crunching or maximum perfomance requirements
Where are we now? "Gartner Hype Cycle" by Jeremykemp at en.wikipedia. Licensed under CC BY-SA 3.0 via Wikimedia Commons http://commons.wikimedia.org/wiki/file:gartner_hype_cycle.svg#mediaviewer/file:gartner_hype_cycle.svg
Microservices & Erlang/OTP: how they fit together
How they fit together > Erlang / OTP has everything you need to build production-ready Microservices
How they fit together > fault tolerance / resilience > async communication is the default > amazing monitoring capabilites > tools for upgrading / downgrading running systems
Green Day 2010 Tour by Daniel D Auria. Licensed under CC BY-SA 2.0
Thank you! > Questions? > Comments? Christoph Iserlohn christoph.iserlohn@innoq.com