StaffCoder
Spring Boot
Spring BootSpring Boot 4.1Java 25
12 modules · 48 challengesSign up
Module 10 · Events and Messaging

Airport Gate Change Broadcast System

hard—No data yet

Problem statement

Complete the broadcast core of an airport gate change system: every committed gate change is stored in per-flight sequence and fanned out to connected subscribers, and a reconnecting subscriber catches up on exactly what it missed.

Requirements

GateChangeRecorder

storeGateChange(GateChangeMessage message)

  • React to every published gate change from inside the same unit of work that changes the gate, so a change that rolls back stores no event
  • Save a GateChangeEvent carrying the message's flightId, oldGate, newGate and occurredAt, the moment the change happened
  • Assign each stored event its seq inside that committing unit of work: the first stored event of a flight has seq 1, and every later event of the same flight has the previous seq plus 1
  • Sequence numbers are tracked per flight: a change to one flight never advances another flight's sequence
  • A change that rolls back consumes no sequence number: the next successful change of that flight continues the unbroken run

GateBroadcaster

deliverCommittedChange(GateChangeMessage message)

  • React to a gate change only after its unit of work has committed successfully; a change that rolls back is never delivered to any subscriber, and deliveries already made stay untouched
  • Deliver the newly stored event to every connected subscriber exactly once, through the subscriber's deliver method; what a subscriber holds is the stored record itself, matching the event store
  • A disconnected subscriber receives nothing while it is disconnected; its events are still stored for it to catch up on later
  • Deliveries reach every subscriber in stored order: two rapid changes to one flight arrive as seq 1 then seq 2, and interleaved changes to different flights keep each flight's events in seq order
  • Advance the subscriber's cursor as you deliver, through moveCursorTo, so no event is ever delivered to the same subscriber twice

replay(Subscriber subscriber)

  • Runs when a subscriber reconnects through the registry: deliver exactly the events stored while the subscriber was disconnected, in stored order, and advance the cursor past them
  • A subscriber that missed nothing receives nothing on reconnect, and reconnecting a second time in a row delivers nothing further: every stored event reaches each subscriber at most once
  • Each subscriber catches up independently: reconnecting one subscriber never delivers anything to the other
  • Replay and live delivery join up: a subscriber that reconnects and then sees further live changes holds one duplicate-free log in stored order

Provided flight endpoint and subscribers

  • PATCH /flights/{id}/gate changes a flight's gate inside one atomic unit of work and publishes a GateChangeMessage carrying the flightId, oldGate, newGate, and occurredAt of the change
  • A support FaultInjector can force that unit of work to fail after publishing; the whole change then rolls back and the request answers 500 Internal Server Error with error message: "Injected failure after publish"
  • The SubscriberRegistry holds two subscribers, DISPLAY and CREW, each with a connected switch, an ordered in-memory delivery log, and a cursor that remembers the last event it received; reconnect flips the switch back on and hands the subscriber to your replay method
  • GateChangeEventRepository ships empty for whatever reads the recorder and broadcaster need; three flights are seeded at startup for manual play

Sample Requests & Responses

Expand to view details on sample requests and responses.

PATCH /flights/1/gate

Request:

{
   "gate": "B2"
}

Response (200 OK):

{
   "id": 1,
   "flightNumber": "AV-201",
   "gate": "B2"
}

PATCH /flights/2/gate

Request:

{
   "gate": "A9"
}

Response (200 OK):

{
   "id": 2,
   "flightNumber": "BX-77",
   "gate": "A9"
}

More in Events and Messaging

See the module
Warehouse Stock Change NotifierThis problem covers sending one change out to several handlers that run in the background, independently of each other.—No data yethardOrder Lifecycle Event ChainThis problem covers moving an order through its stages, each handler advancing one step and triggering the next.—No data yethardLoyalty Points Award ListenerThis problem covers reacting to a purchase only once it has actually been saved for good.—No data yethard

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.