Data and states
Which changes to the collection tour must apply together, and what remains protected after completion?
The contracts require an authoritative datastore for collection route T-38. An assumed load of 9800 kg plus 200 kg of planned additional loading reaches exactly 10000 kg. A further 1 kg exceeds the case limit. Estimated bin masses and the confirmed accepted mass are separate values; their difference requires investigation rather than automatic overwriting. The state is saved with its command result so the same command remains recognisable after a restart.
Starting point A device event identifies its route and bin.
Assumptions for the example case
Original fictional example design. A municipal collection service for non-hazardous waste uses its own operational records and confirmed handovers. The illustrative load limit is 10000 kg; additional planned loading is allowed only if total mass remains ≤ 10000 kg. All figures and test targets are illustrative assumptions.
Authoritative data and permitted state transitions
Data and states
Each emptying takes effect once per bin and route. Completion requires a handover record and resolved discrepancies.
Domain entities and relationships
| Entity | Authoritative attributes | Relationship |
|---|---|---|
| Collection route | T-38; vehicle, start and assigned bins | A route has many collection work orders. |
| Bin work order | B-38 within the route; outcome | Ends with the bin emptied or a documented exception. |
| Bin-emptying event | Device, event identity, time and reported mass | One effective emptying per route-and-bin work order. |
| Handover record | U-38; load, receiving facility and confirmed mass | Route completion requires handover and resolved exceptions. |
Collection route
- Authoritative attributes
- T-38; vehicle, start and assigned bins
- Relationship
- A route has many collection work orders.
Bin work order
- Authoritative attributes
- B-38 within the route; outcome
- Relationship
- Ends with the bin emptied or a documented exception.
Bin-emptying event
- Authoritative attributes
- Device, event identity, time and reported mass
- Relationship
- One effective emptying per route-and-bin work order.
Handover record
- Authoritative attributes
- U-38; load, receiving facility and confirmed mass
- Relationship
- Route completion requires handover and resolved exceptions.
Permitted state transitions
| Starting point | Target | Precondition |
|---|---|---|
| geplant | unterwegs | The collection team confirms the route start and assigned bins. |
| unterwegs | übergabe_offen | The route has finished collection and awaits a receiving record. |
| übergabe_offen | übergeben | The receiving facility confirms the same load. |
| übergabe_offen | klärfall | The accepted mass or record assignment differs. |
| übergeben or klärfall | abgeschlossen | Records officers confirm the complete chain of evidence and the resolution of discrepancies. |
| abgeschlossen | terminal | Duplicate reports cause no second emptying; corrections receive separate records. |
geplant
- Target
- unterwegs
- Precondition
- The collection team confirms the route start and assigned bins.
unterwegs
- Target
- übergabe_offen
- Precondition
- The route has finished collection and awaits a receiving record.
übergabe_offen
- Target
- übergeben
- Precondition
- The receiving facility confirms the same load.
übergabe_offen
- Target
- klärfall
- Precondition
- The accepted mass or record assignment differs.
übergeben or klärfall
- Target
- abgeschlossen
- Precondition
- Records officers confirm the complete chain of evidence and the resolution of discrepancies.
abgeschlossen
- Target
- terminal
- Precondition
- Duplicate reports cause no second emptying; corrections receive separate records.
Atomic changes and versions
- Content reference
- An assumed load of 9800 kg plus 200 kg of planned additional loading reaches exactly 10000 kg. A further 1 kg exceeds the case limit. Estimated bin masses and the confirmed accepted mass are separate values; their difference requires investigation rather than automatic overwriting.
- Shared commit
- The collection route API validates the route, bin, device event, action time and reported mass. 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 devices report the same route-and-bin work order: in either order, exactly one emptying is accepted. Conflicting content creates an investigation case instead of a second emptying.
- Terminal completion
- After abgeschlossen, replay increases neither the count nor the mass. New conflicting evidence opens a linked correction case and leaves the completion record unchanged.
Cover the full scope of the case
- Concrete rule
- The 10000 kg rule applies only to illustrative route planning. Actual overload is recorded truthfully as a discrepancy and handled through the responsible operational procedure. Rejecting a measurement record must not remove that overload from the history. An inaccessible bin receives an exception record rather than an emptying record.
Derive storage needs from access patterns
- Authoritative relational datastore
- A route has many collection work orders, each ending with an emptied bin or a documented exception. 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 the 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.
Each route-and-bin work order records one effective emptying
Each route-and-bin work order records one effective emptying.
Two devices report the same route-and-bin work order: in either order, exactly one emptying is accepted. Conflicting content creates an investigation case instead of a second emptying.
After abgeschlossen, replay increases neither the count nor the mass. New conflicting evidence opens a linked correction case and leaves the completion record unchanged. 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 collection route T-38 are serialised briefly.
- Reassess
- Measurable waiting times when 1000 offline reports arrive from one vehicle after reconnection call for a review of transaction duration.
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 devices report the same route-and-bin work order: in either order, exactly one emptying is accepted. Conflicting content creates an investigation case instead of a second emptying.
- Completion
- After abgeschlossen, replay increases neither the count nor the mass. New conflicting evidence opens a linked correction case and leaves the completion record unchanged.
Apply to your project
Which states must remain protected in your model against late replay?