NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle1 view

Design a distributed system for managing dry-cleaning orders, with offline terminals and disputes.

Practice

AI answer

I would split the system into an online API, an order service, terminal clients, synchronization, payments, and a disputes subsystem. An order is stored as an aggregate containing the customer, items, services, status, price, and change history. Status changes are made through permitted transitions, for example, “accepted” → “in progress” → “ready” → “picked up.”

The terminal stores a local database and a command queue, so it can accept orders and mark them as being processed without a network connection. Each command contains a unique ID, a terminal ID, an order version, and a timestamp. When connectivity is restored, the server applies commands idempotently. Conflicts cannot be resolved by relying only on the device’s clock: the server checks the version and transition rules. Non-conflicting fields can be merged, while status or payment conflicts are sent for manual review. The user can see the synchronization status.

To prevent duplicate payments and orders, we need an idempotency key, a transactional order record, and an outbox for publishing events. Events can be delivered through a broker with retries and deduplication. All changes, including actions made by offline terminals, are written to an immutable audit log.

A dispute is represented as a separate object linked to the order: reason, reported damage or discrepancies, photos, participants, deadlines, and status. Evidence is stored with checksums and upload timestamps; the resolution and compensation are also audited. Access to personal data is restricted by role. Monitoring should show synchronization lag, conflicts, payment errors, and unresolved disputes.