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

Design a distributed system for managing equipment reservations at a university, with priorities and offline operation.

Practice

Asked at

AI answer

Architecture and model

Clients call the API, and the booking service uses PostgreSQL as the source of truth; separate modules handle the equipment catalog, access permissions, notifications, and reports. Core entities: Equipment, Location, Booking, User, PriorityPolicy, BookingEvent. Store the history of status transitions and priority decisions for auditing.

Booking and priorities

Confirming a booking for a single resource must be atomic: a transaction checks for overlapping time intervals and creates the booking. Use a constraint on non-overlapping intervals (for example, an exclusion constraint in PostgreSQL) or lock the equipment row and check again. Statuses distinguish a draft, a pending request, a confirmed booking, a cancellation, and a completed booking.

Set priorities using a transparent policy: role/course, learning objective, request time, and usage limits. Sort the request queue according to the policy, but never silently displace a confirmed booking. If displacement of lower-priority requests is allowed, it must be explicitly stated, communicated, and recorded in the audit log. Do not hold a database lock while requests are being coordinated or external systems are being called.

Offline mode

The client can cache the catalog and schedule with a timestamp, create drafts, and add requests to a local queue. An offline request is not a confirmed booking: the server makes the final decision during synchronization, since another device may have taken the resource. Show an “awaiting synchronization” status and the outcome of any conflict; support resubmission with an idempotency key. For extended network outages, local administrators can be given a limited offline mode with resources allocated in advance and reconciled later.

Reliability and operations

Use university account authentication, role-based authorization, audit logging, and backups. A notification queue and transactional outbox prevent alerts from being lost. Metrics: booking conflicts, synchronization errors, cancellation rate, and response time; regularly test recovery from backups.