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
Identity, content revision and current aggregate version remain separate concepts.
Domain entities and relationships
| Entity | Authoritative attributes | Relationship |
|---|---|---|
| Train service | Operator + operating day + service identifier | A train service has many source reports and exactly one current status version. |
| Timetable version | P-24; stops and scheduled times | Each train service references a defined timetable version. |
| Source report | M-24; source, source version, source time and reception time | Reports remain immutable; older versions do not overwrite newer status. |
| Status projection | Cancellation, forecast and freshness | Derived 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 point | Target | Precondition |
|---|---|---|
| geplant | verspätet | A newer authenticated report for the same service and operating day. |
| geplant or verspätet | ausgefallen | Dispatch confirms the cancellation. |
| ausgefallen | ausgefallen | An older delay report or identical replay leaves the cancellation unchanged. |
| ausgefallen | geplant or verspätet | 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 | archiviert | The 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.
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?