Reactive Programming with Scala and Akka

Harness reactive programming to build scalable and fault-tolerant distributed systems using Scala and Akka

Reactive Programming with Scala and Akka

Learning
Prasanna Kumar Sathyanarayanan, Suraj Atreya

Harness reactive programming to build scalable and fault-tolerant distributed systems using Scala and Akka
$39.99
$49.99
RRP $39.99
RRP $49.99
eBook
Print + eBook
$12.99 p/month

Get Access

Get Unlimited Access to every Packt eBook and Video course

Enjoy full and instant access to over 3000 books and videos โ€“ youโ€™ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

+ Collection
Free Sample

Book Details

ISBN 139781783984343
Paperback256 pages

Book Description

Todayโ€™s web-based applications need to scale quickly to tackle the demands of modern users. Reactive programming is the solution developed to ensure the fault tolerant and robust scaling that is essential for professional applications. Reactive programming in Scala and Akka provides a great platform to develop low latency resilient, concurrent Internet scale applications on the Java Virtual Machine.

This comprehensive guide will help you get to grips with the concepts of reactive programming in order to build a robust distributed system in Scala and Akka. Written in two parts, you will first take a walkthrough of the reactive, asynchronous, and functional concepts in Scala before focusing on Akka and getting to grips with the details of real-world use cases.

Begin with an introduction into functional reactive programming, before moving on to writing asynchronous application with non-blocking constructs in Scala. Get familiar with the concept of actor-based concurrency using Akka, and features such as Akka remoting, routing, and persistence capabilities to build distributed applications. Learn to scale applications using a multi-node Akka cluster and unit test Akka actors and get to grips with state machines and how to implement state-driven actors using Akka. Finally, put your skills to the test with a case study where you will concurrently and asynchronously store and retrieve data from a key value store. By progressively working through the Akka concepts, you will not only be able to write your own distributed system, but also appreciate the hidden complexity within the Akka ecosystem.

Table of Contents

Chapter 1: Introducing Reactive Programming
Introduction
The rise of the data age
Tenets of reactive programming
Responsive
Resilient / fault tolerant
Scalable
Message-driven
Practices complementing reactive programming
Some technical use cases of reactive applications
Tumblr's architecture
Tools of the trade
A word about IDEs
Summary
Chapter 2: Functional Reactive Programming in Scala
Mutability versus immutability
Collections
Lazy val
Function composition
Functors, applicative functors, and monads
Indexing files for searching
Function composition revisited
Ease of unit testing
Summary
Chapter 3: Asynchronous Programming in Scala
Synchronous versus asynchronous programming
Futures
Composing Futures
Building an asynchronous client
Summary
Chapter 4: Akka for Reactive Programming
Concurrency and parallelism
Actor model
Threads and actors
An introduction to Akka
Actor path
The actor life cycle
Deadletters
Actor deathwatch
Actor supervision
Supervision strategies
Summary
Chapter 5: Building Resilient Application with Akka
An introduction to actor routing
Pizza delivery workflow implementation with actor routing
Work pulling patterns
Pizza workflow implementation with the work pulling pattern
Actor mailbox
Summary
Chapter 6: Akka Cluster
Introduction to Akka cluster
Membership life cycle
Elasticsearch RSS links using Akka cluster
Elasticsearch indexing
Setting up Elasticsearch
Installing the Marvel plugin
Summary
Chapter 7: Finite State Machines with Akka
Introducing FSM
Relation to actors
Become/unbecome in actors
Writing FSMs with actors
Implementing FSM for a simple stock price average counter
Implementation of FSM
The Agent service
Summary
Chapter 8: Akka Unit Testing
Introducing ScalaTest
Setting up ScalaTest
Setting up the test environment
Our first ScalaTest code
Matchers
Asserting exceptions
Putting everything together to test the pizza example
A word about fixtures
Other variants of ScalaTest
IDE support
Specs2
Testing Actors with ScalaTest
Summary
Chapter 9: Distributed Systems and Key-Value Stores
Distributed systems
Partitioning of data
Replication
The consensus problem
The CAP theorem
FLP impossibility result
The importance of timing and order
Consistency guarantees
DynamoDB
Conflict-Free Replicated Data Type (CRDT)
A distributed in-memory key value store
Summary

What You Will Learn

  • Explore functional programming using Scala
  • Design an asynchronous, non-blocking shopping cart application using Futures
  • Understand the Akka actor model and the relationship between actors and threads
  • Use the Actor Supervision feature to build a fault tolerant and resilient application
  • Create your own distributed system framework using an Akka cluster
  • Take a look under the hood to gain perspective on the Akka engine
  • See a comprehensive case study of a key value store with concurrent reads and writes
  • Model a finite state machine using state-driven actors

Authors

Table of Contents

Chapter 1: Introducing Reactive Programming
Introduction
The rise of the data age
Tenets of reactive programming
Responsive
Resilient / fault tolerant
Scalable
Message-driven
Practices complementing reactive programming
Some technical use cases of reactive applications
Tumblr's architecture
Tools of the trade
A word about IDEs
Summary
Chapter 2: Functional Reactive Programming in Scala
Mutability versus immutability
Collections
Lazy val
Function composition
Functors, applicative functors, and monads
Indexing files for searching
Function composition revisited
Ease of unit testing
Summary
Chapter 3: Asynchronous Programming in Scala
Synchronous versus asynchronous programming
Futures
Composing Futures
Building an asynchronous client
Summary
Chapter 4: Akka for Reactive Programming
Concurrency and parallelism
Actor model
Threads and actors
An introduction to Akka
Actor path
The actor life cycle
Deadletters
Actor deathwatch
Actor supervision
Supervision strategies
Summary
Chapter 5: Building Resilient Application with Akka
An introduction to actor routing
Pizza delivery workflow implementation with actor routing
Work pulling patterns
Pizza workflow implementation with the work pulling pattern
Actor mailbox
Summary
Chapter 6: Akka Cluster
Introduction to Akka cluster
Membership life cycle
Elasticsearch RSS links using Akka cluster
Elasticsearch indexing
Setting up Elasticsearch
Installing the Marvel plugin
Summary
Chapter 7: Finite State Machines with Akka
Introducing FSM
Relation to actors
Become/unbecome in actors
Writing FSMs with actors
Implementing FSM for a simple stock price average counter
Implementation of FSM
The Agent service
Summary
Chapter 8: Akka Unit Testing
Introducing ScalaTest
Setting up ScalaTest
Setting up the test environment
Our first ScalaTest code
Matchers
Asserting exceptions
Putting everything together to test the pizza example
A word about fixtures
Other variants of ScalaTest
IDE support
Specs2
Testing Actors with ScalaTest
Summary
Chapter 9: Distributed Systems and Key-Value Stores
Distributed systems
Partitioning of data
Replication
The consensus problem
The CAP theorem
FLP impossibility result
The importance of timing and order
Consistency guarantees
DynamoDB
Conflict-Free Replicated Data Type (CRDT)
A distributed in-memory key value store
Summary

Book Details

ISBN 139781783984343
Paperback256 pages
Read More