Preparing your design workspace

Loading the problem and your saved attempt…

Design and Implement a Highway Toll Session Domain

Model idempotent vehicle entry and exit events, one open journey per vehicle, deterministic toll calculation, and a path to partitioned durable processing.

Design classes for a highway toll system and implement its bounded journey core.

For this exercise, assume a highway contains ordered gantries, each with a stable identifier and non-negative kilometer position. A registered vehicle enters at one gantry and later exits at a gantry with a greater position.

Each pass event has a globally unique event ID, vehicle ID, gantry ID, event type ENTRY or EXIT, and timestamp. A vehicle may have at most one open journey.

ENTRY opens a journey; EXIT closes the matching open journey and charges a configured non-negative base fee plus a configured number of integer cents per traveled kilometer.

Duplicate event IDs return the original outcome, conflicting reuse is rejected, an EXIT without an open journey and a second ENTRY are rejected without changing state, and timestamps for one vehicle may not move backward. Use integer cents and exact integer kilometer positions.

Model the objects, public contracts, state transitions, and interactions, then implement the in-memory event-processing core with injected gantry and tariff repositories.

Route choice, payment collection, license-plate recognition, tax, discounts, refunds, persistence technology, and multi-highway trips are outside the implementation. A follow-up asks how to scale the same per-vehicle ordering and event-idempotency contract across partitions and recover from process failure.