Interview concept

Resource-Oriented REST Design

Asked of: Software Engineer

Last updated

A clean REST API decision flow showing resource-based URLs, HTTP method choice, validation, idempotency, concurrency checks, and outcome status codes.

What's being tested

The interviewer is testing whether you can model an API around durable resources and their relationships rather than exposing database tables or RPC-shaped actions. You should demonstrate sound choices for URLs, HTTP methods, status codes, representations, validation, pagination, concurrency, and error behavior. DoorDash operates APIs spanning consumers, merchants, dashers, orders, payments, and delivery workflows, so correctness under retries, concurrent updates, partial failure, and evolving clients matters as much as a clean endpoint list.

Core knowledge

  • Resource modeling identifies nouns with independent identity and lifecycle: /orders/{orderId}, /orders/{orderId}/items, and /couriers/{courierId}/location. Avoid verbs such as /createOrder unless the operation is genuinely an action that cannot be represented as resource creation.

  • HTTP method semantics should be explicit: GET retrieves, POST creates or triggers a non-idempotent operation, PUT replaces a known resource, PATCH applies a partial update, and DELETE removes or deactivates one. Do not use POST for every mutation.

  • Idempotency means repeating a request produces the same intended effect. GET, PUT, and DELETE are conventionally idempotent; POST usually is not. For order placement or payment, accept an Idempotency-Key, persist the key with the result, and return the original response on retry.

  • HTTP status codes communicate machine-readable outcomes: 201 Created with a Location header for creation, 200 OK for a returned representation, 204 No Content for successful empty responses, 400 for malformed input, 404 for absent resources, 409 for state conflicts, 412 for failed preconditions, and 429 for throttling.

  • Representation design should separate the public contract from internal persistence. Return stable identifiers, explicit timestamps such as created_at and updated_at, enum values with documented evolution rules, and links or nested objects only when they serve the client’s use case.

  • Validation has multiple layers: syntactic validation checks types and formats; semantic validation checks business rules; authorization checks whether the caller may perform the operation. For example, a valid UUID does not imply that the caller may modify that order.

  • Pagination should be cursor-based for large or changing collections: return items plus a next_cursor, where the cursor encodes a stable ordering such as (created_at, id). Offset pagination is simpler but can skip or duplicate records as rows are inserted or deleted.

  • Filtering and sorting need bounded, documented behavior. Prefer allowlisted fields such as status and created_after; reject arbitrary SQL-like expressions. Stable sorting requires a tie-breaker, for example ORDER BY created_at DESC, id DESC, to make pagination reliable.

  • Optimistic concurrency control prevents lost updates. Return an ETag or version, require If-Match on updates, and respond with 412 Precondition Failed when the resource changed. A last-write-wins update is simpler but can silently overwrite another actor’s change.

  • State transitions should enforce a server-side state machine. An order might move from created to confirmed, preparing, picked_up, and delivered; reject invalid transitions with 409 Conflict rather than allowing clients to mutate a status field arbitrarily.

  • Authentication and authorization are separate concerns. A bearer token may identify the caller, while resource-level authorization determines whether that consumer, merchant, courier, or internal service can access a specific order. Prevent insecure direct object references by checking ownership or policy on every request.

  • Compatibility and observability are part of the API contract. Prefer additive changes, tolerate unknown response fields, deprecate rather than abruptly remove fields, and emit request IDs, structured logs, latency metrics such as `p99`, and audit events for sensitive mutations.

Worked example

No concrete interview title was supplied, so use this representative prompt: “Design a REST API for creating and tracking a DoorDash order.” In the first 30 seconds, clarify whether the API serves consumers or internal clients, whether payment is synchronous, which order states must be exposed, expected read/write volume, and whether clients retry requests. Organize the answer around resource modeling, lifecycle/state transitions, consistency and idempotency, authorization, and read scalability. Model POST /orders as creation with an idempotency key, GET /orders/{id} for retrieval, and perhaps POST /orders/{id}/cancellation if cancellation is an explicit domain command rather than a generic field update. Explain that order creation should persist the request key and final result atomically enough that a timeout followed by a retry cannot create two orders. Use 409 Conflict for an invalid cancellation after preparation has started, and use ETag or a version field if multiple actors can update the order. Explicitly flag the tradeoff between returning a fully expanded order representation and returning a smaller resource with separately fetched restaurant, courier, or tracking data. Close by saying that, with more time, you would define the error schema, authorization policy, event publication behavior, and recovery path when payment succeeds but order creation does not.

A second angle

A related prompt might ask you to design a REST API for a merchant managing menu items and availability. The resource hierarchy may be /merchants/{merchantId}/menu-items, but availability could be modeled as a subresource or a separate schedule resource depending on whether it has its own lifecycle. The key difference is that bulk updates, conditional writes, and scheduled future changes may matter more than a single order’s state machine. You should discuss PATCH semantics, validation of prices and modifiers, authorization by merchant location, and concurrency when a merchant dashboard and an automated inventory service update the same item.

Common pitfalls

Pitfall: Treating REST as “URLs plus JSON” and ignoring semantics. Saying every operation should be POST /doSomething misses idempotency, caching, status codes, conditional requests, and the resource lifecycle; explain why each operation maps to a method or explicit domain action.

Pitfall: Designing directly from database tables. Exposing /orders_table or returning internal columns couples clients to storage and makes future migrations painful; present a stable domain representation with deliberate relationships, field names, and compatibility rules.

Pitfall: Claiming retries are handled because the server is “stateless.” Network timeouts occur after the server may have committed work, so a robust answer names idempotency keys, durable deduplication state, replayed responses, and the retention window for those keys.

Connections

Expect pivots to event-driven architecture, distributed transactions, rate limiting, API versioning, and authorization policy. Resource mutations may also lead to questions about an outbox pattern, cache invalidation, webhooks, and eventual consistency between order, payment, and delivery services.

Further reading

Related concepts