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

Design a system for managing access to a warehouse, with zones, roles, and an audit of every operation.

Practice

Asked at

AI answer

Architecture

  • Identity Provider is responsible for employee authentication (SSO, MFA) and issues a short-lived token containing the user ID and status.
  • Access Control Service accepts requests to enter zones and perform operations on resources. It checks the applicable rules and returns an allow/deny decision with a reason.
  • Management Service allows administrators to create zones, assign roles, and issue temporary permissions.
  • Audit Service reliably stores every decision and administrative change.
  • Access points—door controllers or terminals—call the service over a secure channel. A safe policy is defined in advance for network outages: for example, critical zones remain locked, while authorized temporary passes are available locally for a limited time.

Access Model

Zones and resources are described in a registry. Roles define typical permissions, such as warehouse clerk, inventory auditor, and administrator; assigning a role to a user is limited by zone and validity period. Checks take into account not only the role, but also the context: whether the employee is active, the shift time, the status of the access badge, and whether the operation is permitted in that zone. This combines RBAC with constrained attributes (ABAC).

Example rule: “A warehouse clerk may enter zone A during their shift and perform receiving operations, but may not change access settings.” The principle is least privilege; denial is the default outcome.

API and Storage

Key request: POST /access-decisions with user_id, zone_id, action, resource_id, and the device ID. The response contains the decision, decision_id, and reason. Role and rule changes are made through a separate administrative API with authorization checks and confirmation for critical changes.

A relational database stores users, zones, roles, assignments, rules, and their validity periods. Rule changes are versioned. Only computed permissions with a short TTL may be cached, with mandatory invalidation when access is revoked.

Auditing and Operations

For each request, record the time, user, zone, action, device, result, reason, policy version, and correlation_id. The log also includes entries and exits, denials, role changes, and administrative actions. Events are sent asynchronously to a separate storage system with restricted access, integrity controls, and a retention policy; the log cannot be modified through the application's regular interface. Loss of an audit record must trigger an alert, and critical operations must not proceed without confirmed auditing.

The service must be idempotent for repeated requests from devices, provide latency and failure metrics, support redundancy, and have a verifiable recovery procedure. Tests should cover the “user—role—zone—operation” matrix, permission expiration and revocation, concurrent policy changes, and operation during connectivity loss.