ADR 0019: The DockAppointment moves to dock-scheduling (strangler stages B and C)
Status
Accepted (2026-11-05). Companion of dock-scheduling's ADR 0002 (aggregates,
invariants) and ADR 0003 (consumed contracts and local copies), and part of
plan YD-0002. Amends ADR 0002 (the
DockAppointment aggregate and its invariants leave this context),
ADR 0003 (a third local copy) and
ADR 0004 (the four
dockappointment types are legacy). Does not edit those ADRs: it supersedes the
statements named below.
Amended by ADR 0020: point 2 and the Consequences on rescheduled appointments (the copy also follows DockAppointmentRescheduled and DockAppointmentDoorReassigned).
Amended by ADR 0022: point 5 and Rollout step 4 (the backfill command, the legacy encoders and Replay are gone; the deprecated GETs and the 410 routes stay pending a decision; no legacy event can be produced any more).
Context
A dock appointment is a promise about a door and a time window. Deciding it
needs a calendar (opening hours, closures, tolerance, overlap rules) and the
yard's view of who is at the gate; inbound-receiving has neither. It owned the
aggregate only because it was the first context to need one. The new
dock-scheduling context owns the calendar, and yard-management owns arrivals
(POST /visits), door occupation and release.
The move follows the fleet's strangler pattern for moving an aggregate between contexts (see the inventory-storage to product-master move of the SKU classification, ADR 0034 there):
- A. dock-scheduling runs a legacy importer on this context's topic (done there, not here).
- B. this context re-announces its history so the importer can rebuild every appointment.
- C. this context stops deciding appointments and keeps a read-only copy.
- D. readers (warehouse-planning) switch to dock-scheduling's events.
- E. decommission after cluster verification.
This ADR covers B and C. What this context still needs from an appointment is small: when a receipt is opened against one, it must exist, cover the ASN and not be cancelled, and the receipt takes its door code from it.
Decision
-
dock-scheduling owns the DockAppointment.
POST /appointments,POST /appointments/{appointmentId}/check-insandPOST /appointments/{appointmentId}/cancellationsanswer 410 with the problem typeappointment-moved; thedetailnames the operation to call in dock-scheduling (booking, cancelling) or yard-management (the gate check-in, from which dock-scheduling derives the appointment's check-in). The routes sit outside theIdempotency-Keymiddleware, so a client is told where to go whatever it sent; the OpenAPI marks themx-retired: trueand the REST guideline lint treats them accordingly. The use cases (BookAppointment,CheckInAppointment,CancelAppointment), the id generator for appointments and the per-door overlap rule (Schedule.CheckNoOverlapand its advisory lock) are deleted: nothing calls them. This context raises noDockAppointment*event any more.CloseReceiptno longer completes the appointment nor raisesDockAppointmentCompleted: the door release recorded in yard-management does that, through dock-scheduling.ReceiptClosedand every other receipt and ASN event are unchanged. Walk-in receipts (no appointment) are unchanged. The MCP and A2A surfaces were read-only (ADR 0005, 0016, 0018): they keepget_appointment/list_appointments, now over the copy. -
appointmentsbecomes a local copy. The table and its ASN-coverage table stay and are fed by a new consumer,DockAppointmentConsumer(consumer namedock-appointment-copy), of dock-scheduling'swarehouse.dock-scheduling.events. It acts on two types only,com.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentBookedand...DockAppointmentCancelled(the payloads are restated inapis/asyncapi.yaml, never imported); every other type on the topic (Rescheduled,NoShow, closures) is committed past, and a payload that breaks a rule of this context is skipped with a WARN. Reschedules do not change ASN coverage and are not needed.- Only
direction=INBOUNDappointments are copied; anOUTBOUNDone cannot carry a receipt. - Version guard. Both events carry dock-scheduling's aggregate
version; an event is applied only if it is greater than the stored one. Redelivery, replay and reordering are harmless. Migration 0005 resets the existing rows to version 0 and drops the aggregate guard (version >= 1), so any dock-scheduling version overwrites a legacy row. A later Booked refreshes the data of a cancelled appointment but never revives it. - The CloudEvents
idclaim (processed_events) and the upsert commit in one unit of work; the offset is committed afterwards. - No loop. Applying an event writes nothing to the outbox: the use cases
(
ApplyDockAppointmentBooked,ApplyDockAppointmentCancelled) have no outbox, and a unit test, a BDD scenario and a real-Postgres test pin that the outbox stays empty. - The consumer always runs, like the three other local-copy consumers; an
unset
DOCK_APPOINTMENT_CONSUMER_GROUPis a boot error (chart valueconfig.dockAppointmentConsumerGroup, required). There is no off switch.
- Only
-
Receipts read the copy.
OpenReceiptwith anappointmentIdrequires the appointment to exist (422unknown-appointment), to cover the ASN (422asn-not-on-appointment) and not to be cancelled (409appointment-cancelled). It no longer requiresCheckedIn: the arrival is a yard-management fact this context does not see. The receipt keeps the appointment's door code. -
GET stays, deprecated.
GET /appointmentsandGET /appointments/{appointmentId}read the copy, are markeddeprecated, and go at stage E. The copy only holdsBookedandCancelled;CheckedInandCompletedsurvive only on legacy rows.versionandETagare dock-scheduling's. -
Stage B: the backfill command. The main binary has a one-shot subcommand,
api republish-appointments(e.g.kubectl exec deploy/inbound-receiving -- ./api republish-appointments): it needs onlyDATABASE_URL(no broker, no HTTP server, no consumer, no migrations: the running pod owns the schema), pages through every stored appointment in id order, and for each enqueues, through the transactional outbox and on the integration topic only, the legacy events its state implies:DockAppointmentBooked, thenDockAppointmentCheckedInfor aCheckedInorCompletedrow, thenDockAppointmentCancelledorDockAppointmentCompleted. The running pod's relay publishes them. It prints the count. Timestamps are the row's own (booked, last change, and for a completed row the opening of its first receipt as the check-in moment). It does not write the analytics topic: re-announcing history to dock-scheduling is no new occurrence for this context's own analytics. It is idempotent in effect: dock-scheduling's importer is idempotent byappointment_id, and a second run only repeats messages. The legacy encoder mapping (Encoderfor the integration topic,AnalyticsEncoderfor the events already on the analytics stream) is kept for this command only, and the domain keeps aReplaythat rebuilds a legacy row's event sequence; they go at stage E. Order: run it after dock-scheduling's importer is deployed and before routing traffic to dock-scheduling for booking.
Consequences
- One owner decides appointments; the 410 makes a stale client fail loudly instead of writing to a store nobody reads.
- Receipts keep working without calling anyone: the copy is local and a receipt only needs door, coverage and cancelled-or-not. Between deploy and the first booking event, appointments created before the cutover are served from their legacy rows (version 0), which dock-scheduling's importer then confirms.
- A receipt can be opened on an appointment that dock-scheduling has rescheduled, no-showed or completed: those transitions are not consumed. Only a cancellation blocks a receipt. The door on the receipt is the one on the copy, which a Rescheduled event does not refresh.
- The analytics stream keeps the legacy
DockAppointment*events already on it and the projector keeps counting them; no new ones are produced, so the appointments block of the receiving-performance report stops growing. Moving that report to dock-scheduling's events is a follow-up, not part of this ADR. - Removing the per-door overlap rule and the advisory lock is safe only because nothing books here; dock-scheduling enforces overlap with its own constraint.
- The REST guideline lint gains one narrow exemption (
x-retired: true: a retired operation documents a 410 and no success response, and needs no idempotency key); the success-response rule moves intorestGuideline.jsso live operations are still checked.
Rollout and decommissioning
- Deploy dock-scheduling with the legacy importer (stage A).
- Merge and deploy this change: the migration runs at boot, the consumer joins
its group, the writes answer 410. Set
DOCK_APPOINTMENT_CONSUMER_GROUP(infra change in the same apply). - Run
api republish-appointmentsand compare counts: appointments here == dock-scheduling'slegacy-importrows. - Stage D readers switch; stage E removes the deprecated GETs, the backfill
command, the legacy encoders and
Replay, and marks the old types retired.