Skip to content
C.W.K.
Stream
Lesson 01 of 04 · published

Write Before Show

~11 min · append-only, write-before-show, durability, projection

Level 0Cold Iron
0 XP0/36 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Write Before Show

Visible state is a projection. The board, cockpit, winner card, and queue badge are views assembled from durable facts. If a screen changes before the fact is written, a crash can leave the user remembering a state the system cannot prove ever existed.

Write-before-show reverses the temptation. Validate a transition, append the event and artifact address in one durable boundary, commit, then publish the projection. A client may be briefly stale, but it can refresh into truth. A client shown unwritten success can only refresh into contradiction.

This matters most at exciting moments: seat acceptance, submission, judge selection, verdict, unseal. Those are exactly where optimistic UI feels attractive and where losing an event destroys trust. Optimism may show 'sending' or 'pending'; it must not show a terminal fact before persistence succeeds.

The trail therefore is not an audit feature added later. It is the source from which operational state can be rebuilt and UI truth can be explained.

Persist the cause before projecting the effect. A stale screen can refresh; an unwritten success cannot be recovered.

Code

The write-before-show transition·python
TERMINAL = {"submitted", "accepted", "unsealed", "decided"}


class Crash(Exception):
    pass


def transition(trail, screen, command, *, crash_after_show=False):
    """Flip the order and recoverability changes completely."""
    if command["state"] in TERMINAL:
        trail.append(command)            # 1) persist first
        if crash_after_show:
            raise Crash("died after writing — recoverable")
        screen.append(command["state"])  # 2) only then show
    else:
        screen.append("pending")         # in-flight may be shown early
    return trail, screen


trail, screen = [], []
try:
    transition(trail, screen, {"state": "submitted", "seat": "A"},
               crash_after_show=True)
except Crash as exc:
    print(exc)

# The screen is empty but the fact survived -> a refresh returns to truth.
assert screen == [] and trail[0]["state"] == "submitted"
print("screen:", screen, "| trail:", trail)

External links

Exercise

Pick a terminal UI action and write the persistence boundary that must complete before the label changes.
Hint
Name the exact event whose absence would make the visible state unverifiable.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.