Share
Embed
Introduction to Building Distributed Systems with Scala and Akka
We explore the reasons for building distributed systems framed around the "fallacies of distributed computing". We contrast those fallacies against the requirements, constraints, and realities of building a modern system today, using Scala and Akka for all examples.
Kevin Webber
April 09, 2015
Transcript
57 slides
-
Who$is$Typesafe? • Typesafe)is)a)technology)company)providing)stewardship)for) open7source)so9ware)targe:ng)the)JVM • Scala)7)a)hybrid)object7func:onal)programming)language • Play)7)an)MVC)framework • Akka)7)a)concurrency)toolkit)
• Apache,Spark*)7)a)fast)and)general)engine)for)big)data) processing)(streaming,)SQL,)machine)learning,)and)graph) processing) -
Physical)factors)leading)to)change • Expensive*hardware*→*cheap&hardware • A*single*machine*→*clusters&of&machines • A*single*core*→*mul3ple&cores • Slow*networks*→*fast&networks •
Small*data*snapshots*→*big&data,&streams&of&data -
New$skills$demanded$by$industry • Local'→'distributed • Impera.ve'→'func,onal • Security'agnos.c'→'security1aware • Single'database'→'reads/writes1across1many1data1stores •
Batch'processing'→'streams1of1data,1real6,me1analy,cs -
New$skills$demanded$by$industry • Local'→'distributed • Impera.ve'→'func,onal • Security'agnos.c'→'security1aware • Single'database'→'reads/writes1across1many1data1stores •
Batch'processing'→'streams1of1data,1real6,me1analy,cs • Ops'→'DevOps -
Thread'based* concurrency • Shared(mutable(state • Impera1ve,(sequen1al,(side7effec1ng • Threads(for(concurrency • Locks,(monitors,(etc
• Implementa)ons( • Java(Enterprise(Edi1on,(Ruby(on(Rails -
Message&driven, concurrency • Isolated*state • Asynchronous*message*passing* between*mailboxes • Process*isola:on*for*fault*tolerance •
Actors*can*live*in*different*thread*pools,* JVMs,*nodes,*or*clusters • Implementa)ons* • Erlang,*Play,*Akka -
Event&driven*concurrency • Thread(based+event+loops • Typically+single+threaded • Popular+among+JavaScript+frameworks • Can+lead+to+the+pyramid(of(doom •
Implementa)ons+ • Node.js,+Twisted+Python,+ EventMachine+(Ruby) -
Fallacies(of(distributed(compu2ng • The$network$is$reliable"→"build"systems"that"func3on"even" when"integrated"systems"go"dark • Latency$is$zero"→"there's"no"way"to"change"the"speed"of"light • Bandwidth$is$infinite"→"using"that"fancy"JS"framework"is" wonderful"un3l"it"blocks"page"loading"across"100,000"browsers •
The$network$is$secure"→"integra3on"points"can"introduce" vulnerabili3es -
Fallacies(of(distributed(compu2ng • Topology'doesn’t'change"→"moving"applica.ons"to"the"cloud" gives"the"ability"to"change"topology"at"will;"add"new"app"servers," scale"on"demand,"etc • There'is'one'administrator"→"external"systems"have" performance,"availability,"or"security"issues"that"you"have"no" direct"influence"over •
Transport'cost'is'zero"→"ask"anyone"doing"video"streaming" online"if"transport"costs"are"zero,"transport"is"priced"like"any" commodity -
Side%effect)free)func.ons)enable)parallelism val lastNames = List("Smith","Jones","Frankenstein","Bach","Jackson","Rodin").par // lastNames: scala.collection.parallel.immutable.ParSeq[String] = //
ParVector(Smith, Jones, Frankenstein, Bach, Jackson, Rodin) val res0 = lastNames.map(_.toUpperCase) // toUpperCase, higher-order function // res0: scala.collection.parallel.immutable.ParSeq[String] = // ParVector(SMITH, JONES, FRANKENSTEIN, BACH, JACKSON, RODIN) • Crea&ng)a)parallel)collec&on)is)simple • Parallel)opera&ons)are)implemented)with)divide)and)conquer) style)algorithms)that)parallelize)well -
Enable'concurrency'in'a'transparent'way import scala.util.{Success, Failure} // obtain a future list of
recent posts // executes on a different thread pool val f: Future[List[String]] = future { session.getRecentPosts } // success and failure callbacks f onComplete { case Success(posts) => for (post <- posts) println(post) case Failure(t) => println("An error has occured: " + t.getMessage) } -
Message&passing&to&a&remote&worker val remoteGameActor = system.actorOf( GameActor.props.withDeploy(Deploy(scope = RemoteScope(address))), name =
“gameActor”) val remoteGameActor = context.actorSelection( “akka.tcp://[email protected]:2552/gameActor") remoteGameActor ! message -
Web$Services$Engineer,$Apple Key$Qualifica,ons • Experience*in*developing*web2services*in*a*commercial*se6ng* and*familiar*with*HTTP,*REST,*JSON • Know*how*to*write*reliable,*resilient,*unit2tested,*performant,* baEle2tested*code • Deep*experience*in*any*one*of*Java,*Scala,*C*,*C#,*F#
• Familiar*with*funcKonal*and*reacKve*programming*concepts -
Do#I#expect#College#graduates#to#be#qualified#for#fully#qualified#to# build#distributed#systems#right#out#of#school? • No!%Building%distributed%systems%is%difficult%and%takes%years%of% experience%to%design%and%implement • Building%blocks%can%be%taught%at%the%College%level,%posi?oning% students%for%future%on@the@job%learning,%e.g,%func?onal,%side@ effect@free%programming •
Teaching%"mechanical%sympathy",%i.e,%to%understand%the%physical% limita?ons%of%machines/networks%and%how%soHware%is%deployed% and%executed -
Interested(in(learning(more? • What%Is%Reac+ve%Programming?"#"h%p:/ /bit.ly/1Ay3lHR • Reac+veTO"#"h%p:/ /www.meetup.com/Reac;ve#TO • Func+onal%programming%in%Scala%(Coursera)"#"h%ps:/ /
www.coursera.org/course/progfun • Typesafe%Ac+vator"#"h%ps:/ /typesafe.com/community/core# tools/ac;vator#and#sbt