Reassign a Freelancer without Breaking Distributed-System Invariants
After the client rejects an offer, the system selects the next worker from the existing candidate pool. It can reassign a worker up to three times. After the fourth rejection, the task moves to failed status and the client receives a notification. The solution touches eight distributed-system invariants, including idempotency, atomic state-and-event persistence, service boundaries, and delivery order. This is where the models diverge.
8 traps in the task
01Access facade: private services are available only through the facade
02Data denormalization: the city ID is stored on the task; the system does not resolve a city name to an ID at request time
03Idempotency: each attempt needs a unique key, or duplicate events suppress one another
04Atomicity: state and event are written in one transaction through an outbox; events are never published directly
05N+1 problem: data is fetched in a batch instead of through individual calls in a loop
06Cyclic dependencies: services do not call one another in a cycle
07Event-driven entry: the flow enters through the event bus; the subscriber does not make a synchronous call
08Order and ownership: the event is published after persistence; only the state owner changes the status