3 Part II — Cross the process boundary
Steps 11 to 18 take the architecture of part I and split it across five operating-system processes on one computer. The capabilities keep their mailbox names; only the transport underneath changes, from Java objects to files in directories. The first genuinely distributed problem shows up here, and it has nothing to do with ROT13.
3.1 Step 11 — Separate the components
Three processes cannot share a BlockingQueue: every java command starts its own JVM with its own memory, so the mailboxes map would exist three times and each copy would see only its own messages. An external transport is needed.
TCP would do, MQTT would do. The most primitive option is picked deliberately, the filesystem, for a one-line reason: because you can see it. Messages become files you can list with ls and read with cat while the system runs. Primitive here does not mean inferior; part VIII comes back to what the filesystem is genuinely good and bad at.
3.2 Steps 12–13 — A directory becomes a mailbox
The mapping is one line long:
directory = mailbox file = message
publish = create file receive = watch directory
messageBoard/
├── consoleIn/outbox/
├── rot13/inbox/
├── rot13/outbox/
└── consoleOut/inbox/
The Message record gains an optional timestamp, and the file format stays two lines plus an optional third:
TEXT
Hello World
TIMESTAMP: 2026-09-22T10:42:12.123Z
A message written by hand may leave the timestamp out. The TIMESTAMP: marker keeps a payload line that happens to look like a date from being mistaken for metadata; in this tiny format, a final line starting with TIMESTAMP: is reserved.
Jackson could be introduced here and deliberately is not. The point of a ridiculously simple format is that almost nothing hides the architecture — the whole message is readable in any text editor, which is what keeps the attention on who talks to whom.
3.3 Step 14 — The first distributed-systems problem: publication
A reader watching a directory can discover a file before the writer has finished writing it. Hence a publication protocol:
- create a private temporary file;
- write the complete message;
- close it;
- atomically rename it to its final
.msgname; - consumers react only to final files.
Files.writeString(temporary, content);
Files.move(temporary, published, StandardCopyOption.ATOMIC_MOVE);Both halves are needed. The rename is atomic — a reader sees either no .msg file or the complete one — but it protects nothing if readers also pick up .tmp files. .tmp and .msg stay in the same directory so the move cannot cross filesystems, where atomicity would be lost.
Writing and publishing are not the same operation.
3.4 Step 15 — Observe a mailbox with WatchService
Java’s own filesystem observer supplies the consumer half: register a directory for ENTRY_CREATE, block in watcher.take(), and ignore every filename that does not end in .msg.
That also gives a low-tech injection tool. With ActuatorService running as the consumer:
printf 'TEXT\nHello from a file' > messageBoard/consoleOut/inbox/manual.tmp
mv messageBoard/consoleOut/inbox/manual.tmp messageBoard/consoleOut/inbox/manual.msgObserved: nothing happens when the .tmp file appears; the line is printed the moment the rename creates the .msg name. Both accepted formats work, with and without the trailing timestamp.
The architectural point reads producer → filesystem → consumer: the consumer could not tell a human typing mv from a real service. It knows its own inbox, not who writes into it. Egoism survived the process boundary.
3.5 Steps 16–17 — Services and mediator become processes
The three capabilities become three programs, and the mediator a fourth kind of program:
| program | plays | reads | writes |
|---|---|---|---|
SensorService.java |
ConsoleIn | the keyboard | consoleIn/outbox |
ProcessorService.java |
ROT13 | rot13/inbox |
rot13/outbox |
ActuatorService.java |
ConsoleOut | consoleOut/inbox |
the console |
Mediator.java <from> <to> |
the glue | <from> |
<to> |
The mediator is generic: its route is not compiled in, it arrives as two startup arguments. But there is an asymmetry worth keeping in mind: the three capabilities receive their work as messages in a mailbox, while the mediator receives its route as startup configuration, and it has no name and no control mailbox of its own that anyone could write to.
The practical consequence: arguments are read once, so changing the route of a running mediator means stopping it and starting it again. A configuration file would be no different — it is still read at startup. This stays deliberately unfixed until the cost of the distributed mediators has been felt.
3.6 Step 18 — Run the fully external local version
Five terminals, five processes, one local filesystem between them:
java SensorService.java # terminal 1
java Mediator.java consoleIn/outbox rot13/inbox # terminal 2
java ProcessorService.java # terminal 3
java Mediator.java rot13/outbox consoleOut/inbox # terminal 4
java ActuatorService.java # terminal 5Observed: Hello World typed in terminal 1 appeared as Uryyb Jbeyq in terminal 5. The three middle terminals showed nothing new — each mediator prints one “Mediating: …” line at startup, and ProcessorService prints nothing at all. Afterwards each of the four mailbox directories held one .msg file: the same line, copied along the chain.
Count it: five processes for what step 1 did in one statement. This is not the moment to optimise: it is not meant to be comfortable yet.
3.7 What part II moved
| stage | where the topology lives | who could rewire it |
|---|---|---|
| step 1 | inside the capability code | whoever edits that code |
| steps 7–8 | in main(), as mailbox names |
whoever edits main() |
| step 18 | in the two Mediator.java <from> <to> command lines |
whoever starts the processes |
The topology has now left the source code altogether: no .java file contains the route. It lives in what the operator typed, which means a person is currently the orchestrator. What the five-process version bought is real — the wiring can change without touching any program — and what it cost is equally real: five processes, four copies of every message, and a program that no longer stops when you press Ctrl+D.