liveBook · Manning

Separation of concerns

As explained in Akka in Action, Second Edition

Separation of concerns is the division of software into parts whose responsibilities are distinct and independently manageable.

Separation of concerns divides responsibilities so they can be defined and changed independently. In fault-tolerant software, the key split is between normal processing and recovery after failure. When ordinary objects call one another directly, exception handling becomes interwoven with processing: callers may lose input context, buffer work themselves, coordinate concurrent failures with locks, and arrange retries. Functional behavior and recovery behavior then change together instead of remaining isolated. section 5.1.1

Figure 5.1 Processing logs from the FileWatcher, to the LogProcessor, to the Writer, and to the database
CH05_F01_Abraham2

A log-processing pipeline makes the coupling visible: direct calls connect the FileWatcher, LogProcessor, Writer, and database, so an error can propagate back through the call stack and pull recovery concerns into normal processing. section 5.1.1

Actor supervision makes the split explicit. An actor handles its normal messages, while a supervisor wraps its behavior and chooses a recovery action after an exception. The supervisor can restart an actor, replace it with a fresh instance, stop it, or use other routing choices without embedding reconstruction details in the actor’s message-processing logic. While the decision is pending, the failed actor’s mailbox is suspended. section 5.1.2

Figure 5.6 Supervisor wrapping an actor’s behavior and deciding on a recovery action after an exception
CH05_F06_Abraham2

The supervisor wrapper shows recovery as a separate control flow around an actor’s behavior: an exception leads to a supervisory decision rather than becoming ordinary message-processing code. section 5.1.2

Keep the separation useful during fault recovery:

  • Place actors most likely to fail low in the hierarchy, where more actors can handle or monitor their faults. section 5.1.2
  • Keep normal message processing independent from restart, replacement, stopping, and other supervisory decisions. section 5.1.2
  • Avoid direct object coupling when it forces callers to own buffering, retry context, locking, and lifecycle reconstruction. section 5.1.1

Recovering a log processor

A FileWatcher sends work through a LogProcessor to a Writer. With direct object calls, a Writer failure can unwind through the chain and force processing code to participate in recovery. With actors, the LogProcessor can retain its message behavior while a supervisor decides whether the faulty actor restarts, is replaced, or is stopped. section 5.1.1 section 5.1.2

How Akka in Action, Second Edition covers it

How deep it goes
Contrasts tangled direct-call exception handling with actor supervision, then defers lifecycle and supervision-strategy coding details.
Examples
Uses a FileWatcher–LogProcessor–Writer–database pipeline and a supervisor wrapping actor behavior.
What it assumes
Builds from direct object calls, exceptions, and basic actor behaviors before introducing recovery separation.
What you can do after
Apply it via actor supervision by isolating recovery actions from normal message-processing behavior.
How it connects
Connects actor supervision, actor lifecycle, mailboxes, exceptions, and actor hierarchies.

Also explained in

Compare how 22 books explain separation of concerns →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Akka in Action, Second Edition. The section links point to the parts of the book it draws on.