Applied Akka Patterns

Book description

When it comes to big data processing, we can no longer ignore concurrency or try to add it in after the fact. Fortunately, the solution is not a new paradigm of development, but rather an old one. With this hands-on guide, Java and Scala developers will learn how to embrace concurrent and distributed applications with the open source Akka toolkit. You’ll learn how to put the actor model and its associated patterns to immediate and practical use.

Throughout the book, you’ll deal with an analogous workforce problem: how to schedule a group of people across a variety of projects while optimizing their time and skillsets. This example will help you understand how Akka uses actors, streams, and other tools to stitch your application together.

  • Model software that reflects the real world with domain-driven design
  • Learn principles and practices for implementing individual actors
  • Unlock the real potential of Akka with patterns for combining multiple actors
  • Understand the consistency tradeoffs in a distributed system
  • Use several Akka methods for isolating and dealing with failures
  • Explore ways to build systems that support availability and scalability
  • Tune your Akka application for performance with JVM tools and dispatchers

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Conventions Used in This Book
    2. O’Reilly Safari
    3. How to Contact Us
    4. Acknowledgments
  2. 1. The Actor Model
    1. Reality Is Eventually Consistent
    2. Deconstructing the Actor Model
    3. All Computation Is Performed Within an Actor
    4. Actors Can Communicate Only Through Messages
    5. Actors Can Create Child Actors
    6. Actors Can Change Their State or Behavior
    7. Everything Is an Actor
    8. Uses of the Actor Model
    9. Defining Clear Boundaries
    10. When Is the Actor Model Appropriate?
    11. Conclusion
  3. 2. Introducing Akka
    1. What Is Akka?
      1. Akka Is Open Source
      2. Akka Is Under Active Development
      3. Akka Is Distributed by Design
    2. Akka Components
      1. Akka Actor
      2. Child Actors
      3. Remoting: Actors on Different JVMs
      4. Clustering: Automatic Management of Membership
      5. Akka HTTP
      6. TestKit
      7. Contrib
      8. Akka OSGi
      9. Akka HTTP
      10. Akka Streams
    3. Akka’s Implementation of the Actor Model
    4. Akka’s Actors in the Actor Model
      1. Message Passing
      2. Actor Systems
    5. The Akka Typed Project
    6. Conclusion
  4. 3. Distributed Domain-Driven Design
    1. DDD Overview
    2. The Benefits of DDD
    3. Components of DDD
    4. Domain Entities
    5. Domain Value Objects
    6. Aggregates and Aggregate Roots
    7. Repositories
    8. Factories and Object Creation
    9. Domain Services
    10. Bounded Contexts
    11. Conclusion
  5. 4. Good Actor Design
    1. Starting Small
    2. Encapsulating State in Actors
      1. Encapsulating State by Using Fields
      2. Encapsulating State by Using “State” Containers
      3. Encapsulating State by Using become
      4. Mixing Futures with Actors
    3. Ask Pattern and Alternatives
      1. Problems with Ask
      2. Accidental Complexity
      3. Alternatives to Ask
    4. Commands Versus Events
      1. Constructor Dependency Injection
      2. actorSelection via Path
    5. Conclusion
  6. 5. Good Data Flow
    1. Throughput Versus Latency
    2. Streams
    3. Routers
    4. Mailboxes
      1. Unbounded Mailboxes
      2. Bounded Mailboxes
    5. Work Pulling
    6. Back Pressure
      1. Acks
      2. High-Water Marks
      3. Queue-Size Monitoring
      4. Rate Monitoring
    7. Akka Streams
      1. Source
      2. Sink
      3. RunnableGraph
      4. Flow
      5. Junctions
      6. Back Pressure in Akka Streams
      7. Using Akka Streams
    8. Conclusion
  7. 6. Consistency and Scalability
    1. Transactions and Consistency
    2. Strong Versus Eventual Consistency
    3. Concurrency Versus Parallelism
    4. Why Globally Consistent Distributed State Doesn’t Scale
    5. Location Transparency
    6. Delivery Guarantees
      1. At Most Once
      2. At Least Once
      3. Exactly Once Doesn’t Exist (But Can Be Approximated)
      4. How Do You Approximate Exactly Once Delivery?
      5. Cluster Singleton
    7. Scalability
      1. Avoid Global State
      2. Avoid Shared State
      3. Follow the Actor Model
      4. Avoid Sequential Operations
      5. Isolate Blocking Operations
      6. Monitor and Tune
    8. Cluster Sharding and Consistency
      1. Sharding
      2. Sharding in Akka
      3. Shard Key Generation
      4. Shard Distribution
      5. Consistency Boundary
      6. Scalability Boundary
      7. Sharding Aggregate Roots
      8. Persistence
      9. Passivation
      10. Using Cluster Sharding for Consistency
    9. Conclusion
  8. 7. Fault Tolerance
    1. Types of Failures
      1. Exceptions
      2. Fatal Errors in the JVM
      3. External Service Failures
      4. Failing to Meet a Service-Level Agreement
      5. Operating System and Hardware-Level Failures
    2. Isolating Failures
      1. Bulkheading
      2. Graceful Degradation
      3. Isolating Failure by Using Akka Cluster
      4. Controlling Failures by Using Circuit Breakers
    3. Dealing with Failures
      1. Dealing with Exceptions (Let It Crash)
      2. Dealing with External Service Failures
      3. Conclusion
  9. 8. Availability
    1. Microservices Versus Monoliths
    2. Bounded Contexts as Microservices
    3. Fine-Grained Microservices
    4. Cluster-Aware Routers
    5. Distributed Data
    6. Graceful Degradation
    7. Deployment
    8. Staged Deployment/Rolling Restarts
    9. Blue/Green Deployment
    10. Crash Recovery/Operational Monitoring
      1. Health Checks and Application Status Pages
      2. Metrics
      3. Logging
      4. Watchdog Tools
    11. Conclusion
  10. 9. Performance
    1. Isolating Bottlenecks
    2. Tuning Akka
      1. Reduce or Isolate Blocking Sections
      2. Make the Message Process in Less Time
      3. Engage More Actors on Processing the Messages
    3. Dispatchers
      1. The Standard Dispatcher
      2. Pinned Dispatcher
      3. Balancing Dispatcher
      4. Calling-Thread Dispatcher
      5. When to Use Your Own Dispatchers
      6. Increase Parallelism
    4. Conclusion
  11. Afterword
  12. References
  13. Index

Product information

  • Title: Applied Akka Patterns
  • Author(s): Michael Nash, Wade Waldron
  • Release date: December 2016
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491934838