Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Building Distributed Systems with Scala and Akka

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
Tweet

More Decks by Kevin Webber

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. 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) }
  4. 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