System Design Atlas

Rail timetables and disruption information

05 / 10Worked example

Data and states

Which changes to the train service must take effect together, and what stays protected after completion?

The contracts require an authoritative datastore for train service F-24. Service identity combines the operator, operating day and service identifier. A night service belongs to the agreed operating day; reception time and source time remain separate fields. The state is stored with its command result so the same command remains recognisable after a restart.

Starting point Source versions take precedence over arrival order.

Assumptions for the example case

Original fictional design: a regional rail line with dated services, stops and manually confirmed cancellations. An actual-status report is current at age < 90 seconds; at 90 seconds its timestamp is marked stale. All figures and test targets are illustrative assumptions.

Authoritative data and permitted state transitions

Authoritative entities and states

Train service F-24Authoritative entity
Timetable P-24bound version
Disruption report M-24Durable proof
Fahrt F-24 → Fahrplan P-24Applies to the operating day and service
Fahrt F-24 → Störungsmeldung M-24Has 0..n source reports
1geplant → verspätet
2geplant | verspätet → ausgefallen
3ausgefallen → authorised correction only
4→ archiviert (terminal)

Identity, content revision and current aggregate version remain separate concepts.

Service identity combines the operator, operating day and service identifier. A night service belongs to the agreed operating day; reception time and source time remain separate fields.

Domain entities and relationships

EntityAuthoritative attributesRelationship
Train serviceOperator + operating day + service identifierA train service has many source reports and exactly one current status version.
Timetable versionP-24; stops and scheduled timesEach train service references a defined timetable version.
Source reportM-24; source, source version, source time and reception timeReports remain immutable; older versions do not overwrite newer status.
Status projectionCancellation, forecast and freshnessDerived from confirmed reports; reactivation after cancellation requires explicit correction.

Train service

Authoritative attributes
Operator + operating day + service identifier
Relationship
A train service has many source reports and exactly one current status version.

Timetable version

Authoritative attributes
P-24; stops and scheduled times
Relationship
Each train service references a defined timetable version.

Source report

Authoritative attributes
M-24; source, source version, source time and reception time
Relationship
Reports remain immutable; older versions do not overwrite newer status.

Status projection

Authoritative attributes
Cancellation, forecast and freshness
Relationship
Derived from confirmed reports; reactivation after cancellation requires explicit correction.

Permitted state transitions

Starting pointTargetPrecondition
geplantverspätetA newer authenticated report for the same service and operating day.
geplant or verspätetausgefallenDispatch confirms the cancellation.
ausgefallenausgefallenAn older delay report or identical replay leaves the cancellation unchanged.
ausgefallengeplant or verspätetExplicit authorised cancellation correction with the current aggregate version, a newer evidenced source version and a correction reason. An ordinary delay report is insufficient.
geplant or verspätet or ausgefallenarchiviertThe operating day has ended and post-service reconciliation is complete; new status changes are blocked.

geplant

Target
verspätet
Precondition
A newer authenticated report for the same service and operating day.

geplant or verspätet

Target
ausgefallen
Precondition
Dispatch confirms the cancellation.

ausgefallen

Target
ausgefallen
Precondition
An older delay report or identical replay leaves the cancellation unchanged.

ausgefallen

Target
geplant or verspätet
Precondition
Explicit authorised cancellation correction with the current aggregate version, a newer evidenced source version and a correction reason. An ordinary delay report is insufficient.

geplant or verspätet or ausgefallen

Target
archiviert
Precondition
The operating day has ended and post-service reconciliation is complete; new status changes are blocked.

Atomic changes and versions

Content reference
Service identity combines the operator, operating day and service identifier. A night service belongs to the agreed operating day; reception time and source time remain separate fields.
Shared commit
The train service status API validates operating day, service, source version and cancellation reason. It writes the business change, command result and any pending work in one transaction. Commit makes these changes durably visible together. Before commit, rollback ends the attempt without partial effects.
Concurrency
Two reports with source versions 8 and 9 arrive in both orders: version 9 remains visible; version 8 is retained in history and does not overwrite the display.
Terminal completion
After archiving, a new cancellation command produces a conflict; an identical old retry returns its original result.

Cover the full scope of the case

Concrete rule
In the concurrency test, source version 8 is a delay and source version 9 is the confirmed cancellation. Later arrival of version 8 leaves version 9 unchanged. Even a delay report with a higher source version cannot reverse the cancellation; that requires a separate authorised correction command.

Derive storage needs from access patterns

Authoritative relational datastore
A train service has many source reports, exactly one current status version and a reference to a defined timetable version. The design therefore uses a relational metadata store with uniqueness constraints and short transactions. Historical versions remain referenceable; a rebuildable read model must not overwrite authoritative state.
Large content and measurement series
Derived views and extensive measurement or event histories are read separately according to their access patterns. Binding state decisions remain in the authoritative datastore.

Cancellation history retains the reason for each correction

Cancellation history retains the reason for each correction

Cancellation history retains the reason for each correction.

Two reports with source versions 8 and 9 arrive in both orders: version 9 remains visible; version 8 is retained in history and does not overwrite the display.

After archiving, a new cancellation command produces a conflict; an identical old retry returns its original result. The exercise specifies the input and expected result.

Alternative considered
Separate unversioned changes allow an older state to overwrite the newer one.
Trade-off
Changes to train service F-24 are serialised briefly.
Reassess
Measurable waits for 100 reports about the same service in reverse source order call for a review of transaction duration.

Test the correction path

Input and expected result
Explicit transition ausgefallen → geplant or verspätet: authorised dispatch role, same service and operating day, expected current aggregate version, a new command explicitly identified as cancellation correction, newer evidenced source state and correction reason. The new state determines geplant or verspätet. Ordinary delay reports of any higher source version preserve the cancellation. Archived remains terminal. The data-state diagram and model include this separate correction path; the historical cancellation report is preserved. Test: cancellation at source version 9, ordinary delay 10 → still ausgefallen; authorised correction 11 with current version → verspätet; replay → same correction record; stale version or missing permission → conflict or rejection.

Try it yourself

Explain the two possible winner orders in the case contract. Also determine the behaviour after terminal completion.

A hint for your attempt

Content revision and aggregate version have different tasks.

Compare with a possible solution
Concurrency
Two reports with source versions 8 and 9 arrive in both orders: version 9 remains visible; version 8 is retained in history and does not overwrite the display.
Completion
After archiving, a new cancellation command produces a conflict; an identical old retry returns its original result.

Apply to your project

Which states must remain protected in your model against late replay?

Next: train service status and the display projection run separately.