whoami

Lucas Jenß

cat /etc/motd

The Coding Journal ツ — Notes taken on an epic coding journey. Technical solutions, debugging notes, and practical guides from the trenches of software development.

Close-up of white dominoes with black dots standing on green felt surface, shallow depth of field, focused mood

ls -la ~/languages/

total 8
drwxr-xr-x
▶ PHP
▶ Ruby
▶ Scala
▶ C#
▶ JavaScript
▶ Objective-C
▶ Shell Scripting

ls -la ~/toolchain/

total 7
drwxr-xr-x
▶ Typo3
▶ Akka
▶ Capistrano
▶ Git
▶ MAMP
▶ Adobe Illustrator
▶ NSTrackingArea (Cocoa)

uname -a

platforms
drwxr-xr-x
▶ Mac OS X
▶ Unix

Akka supervision strategies: one-for-one and all-for-one

An Akka actor rarely fails alone in a production system. It delegates work to children, reads messages, calls external services and keeps state that other actors may depend on. When an exception escapes, the parent supervision strategy decides whether to restart the failed child, restart every sibling, stop the actor, or escalate the failure further up the hierarchy.

The practical difference is the blast radius of recovery. A one-for-one strategy isolates the faulty child and leaves healthy siblings running. An all-for-one strategy deliberately resets the whole sibling group, which can restore a shared invariant but also discards useful in-memory state. Picking the broader option without understanding that trade-off can turn one bad message into a system-wide disturbance.

That choice becomes concrete in Australian engineering teams, from Melbourne and Sydney hubs to software supporting FIFO mining operations and national retail platforms. Teams often use direct language such as “we’ll run a quick spike” or “that’s a hard stop”, while still needing reliable handling of payment windows, latency and maintenance runbooks. Supervision policy should fit those operational constraints, not merely copy an example from a framework guide.

How the two restart scopes differ

One-for-one is the usual default because independent child actors should be able to fail independently. If a parser actor throws while decoding a document, its supervisor restarts that parser. Other consumers of the same broker keep their current work, queues and counters. This isolation preserves throughput and keeps a recurring fault attached to one actor instead of contaminating unrelated responsibilities.

An all-for-one strategy applies when the direct children are pieces of one logical operation. Imagine a booking coordinator supervising availability, pricing and payment workers that share an in-memory transaction state. If one child breaks an invariant, restarting all three can return the group to a known clean state. The Scala and Akka notes provide useful context on building actor systems in Scala, including where such boundaries tend to sit.

Scope matters: all-for-one covers the supervisor’s direct children, not every actor in the business. Descendants still use their own supervision policy, although they may be stopped when a parent is restarted. This distinction prevents a common mistake—treating a deeply nested workflow as a flat sibling group when it actually contains several independent recovery boundaries.

Choosing a supervision boundary

The first question is not how often an actor fails, but whether its siblings can remain valid after it does. If children can run independently and communicate through messages, one-for-one is usually safer. If they read or mutate shared state without a durable transaction boundary, one child may leave the others with stale assumptions. In that case, a coordinated restart can be less surprising than preserving half of a broken unit.

The choice should then be expressed in code where the supervisor is defined, not left to a global default. Scala’s classic actor API commonly uses OneForOneStrategy(...) and AllForOneStrategy(...); Akka Typed provides corresponding behaviour-level choices. Document the reason beside the declaration. A comment such as “all children share the booking invariant” is more valuable than a bare configuration because it gives reviewers a reason to challenge an overly broad restart policy.

Restarting actors resets volatile state, but it does not reverse emails sent, database writes or payment captures. That makes the strategy a recovery mechanism rather than a rollback mechanism. For an Australian fintech customer processing transactions at the 30 June financial year-end, idempotency keys and durable event records matter more than pretending an in-memory restart can undo completed work. The same rule applies to a managed-service integration serving customers across business hours.

Handling exceptions and escalation

An uncaught exception enters the actor’s failure path; a supervisor does not inspect every message before the code runs. The configured policy then decides what happens within that supervision scope. Retry limits and a time window can eventually escalate a failure to the parent, while deliberately configured directives can stop a child or handle particular exceptions. Those controls are useful, but they should describe business severity rather than hide implementation mistakes behind an endless retry loop.

During a restart, the actor instance is replaced. Its ordinary in-memory fields disappear, while the mailbox belonging to the stable actor path remains available under Akka’s normal restart semantics. Children are stopped during the restart lifecycle and then recreated. Any state needed after recovery must be reconstructed, persisted with Akka Persistence where appropriate, or obtained again from a reliable source; external side effects need their own deduplication controls.

Exceptions and fatal errors also deserve different attention. A recoverable validation problem is better caught close to the request boundary, where a useful response can be produced. A corrupted payload may justify stopping that child until fresh input arrives. An Error generally triggers a more severe path than an ordinary exception, so verify the behaviour in the exact Akka version used by the project instead of assuming every throwable is restartable.

Testing restart behaviour safely

Test the failure, not just the happy path. With Akka TestKit, inject a deterministic exception into a child and use probes to confirm which actors terminate, which messages arrive and how quickly the supervisor recreates the failed instance. Give actors correlation identifiers when a restart could make old and new work look identical in logs. A test that proves one child recovers while its sibling continues is the clearest evidence that isolation works as intended.

An all-for-one test must observe every direct sibling, including actors that never threw the exception. Assert that the shared invariant is restored and that in-flight work is either completed safely or discarded with a clear policy. Also check what happens after repeated failures exceed the retry window. That path often reveals escalation assumptions that ordinary tests miss, particularly when the parent is itself embedded in a larger actor hierarchy.

In production, count restarts by actor path, supervisor and failure type, then alert on abnormal rates. The site’s practical troubleshooting notes illustrate how small operational clues can become valuable incident evidence. Australian on-call teams should agree on who can trigger a deployment or restart during customer-facing trading windows, whether the request comes from Perth or Sydney. Clear ownership prevents a noisy recovery from becoming a second incident.

Practical recommendations for reliable actors

A dependable policy is small, explicit and reviewed with the code that owns the actor graph. The following recommendations keep restart decisions aligned with failure containment and day-to-day maintenance.

  • Start with one-for-one for independent children, reserving all-for-one for siblings whose correctness depends on a shared in-memory invariant.
  • Keep the all-for-one group narrow and document the invariant that makes a collective restart necessary.
  • Make handlers idempotent, persist durable state separately and assume external side effects will survive an actor restart.
  • Add tests and metrics that prove the intended actors restart, the intended actors continue and escalation behaves correctly.

These checks are especially valuable in codebases inherited from older Scala services. Refactoring one child into several asynchronous workers can quietly change the correct supervision scope. Review the dependency graph whenever actor responsibilities move, then update both the implementation and the tests. A short decision record can prevent the next maintainer from mistaking a historical configuration for a deliberate design choice.

Apply the strategy to your next actor design

Use one-for-one as the default isolation tool, and choose all-for-one only when collective recovery protects a genuine shared invariant. Before deploying either policy, write down what state is lost, what external work survives and which direct children are included. That small explanation often reveals a simpler boundary or a missing persistence design.

Now run a controlled failure test, inspect the actor logs and metrics, and confirm the result with the people who support the service. Keep the chosen strategy beside the supervisor definition, then revisit it after the next actor-graph change. Make the next restart decision an explicit, tested part of the system rather than an inherited surprise.


cat ~/interests.json

KeyValue
editorTerminal-first workflow
osMac OS X / Unix
vcsGit, distributed version control
deployCapistrano, cron automation
graphicsSVG, Adobe Illustrator troubleshooting
networkingIP validation, SSH, VPN

git log --oneline --reverse

2013-10-30

Solving SVG import issues in Adobe Illustrator CS6 and CC

When importing an SVG into Illustrator, the operation fails with an unknown error [CANT]. A workaround for this Adobe-side bug.

2013

Solving NDK build issues on OS X

Troubleshooting native development kit compilation problems on Mac OS X.

2013

Programmatically adding PHP generated TypoScript to the backend configuration

Integrating dynamically generated TypoScript into Typo3 backend setups using PHP.

2013

ArgumentError: Could not parse PKey: no start line

Debugging an SSH key parsing error encountered during deployment.

2011-08-04

Validating IP-Addresses in PHP

Using PHP filter functions with flags like FILTER_FLAG_IPV4 and FILTER_FLAG_IPV6, and understanding how filter_var handles reserved IP addresses.

2011-07-09

Cocoa: Using NSTrackingArea

A short tutorial on using Cocoa's NSTrackingArea to capture mouseEntered and mouseExited events.


cat ~/contact.txt

github: github.com/x3ro
stackoverflow: x3ro
coderwall: coderwall.com/x3ro
twitter: @x3rames