Resource-Oriented REST Design
Asked of: Software Engineer
Last updated

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/createOrderunless the operation is genuinely an action that cannot be represented as resource creation. -
HTTP method semantics should be explicit:
GETretrieves,POSTcreates or triggers a non-idempotent operation,PUTreplaces a known resource,PATCHapplies a partial update, andDELETEremoves or deactivates one. Do not usePOSTfor every mutation. -
Idempotency means repeating a request produces the same intended effect.
GET,PUT, andDELETEare conventionally idempotent;POSTusually is not. For order placement or payment, accept anIdempotency-Key, persist the key with the result, and return the original response on retry. -
HTTP status codes communicate machine-readable outcomes:
201 Createdwith aLocationheader for creation,200 OKfor a returned representation,204 No Contentfor successful empty responses,400for malformed input,404for absent resources,409for state conflicts,412for failed preconditions, and429for throttling. -
Representation design should separate the public contract from internal persistence. Return stable identifiers, explicit timestamps such as
created_atandupdated_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
statusandcreated_after; reject arbitrary SQL-like expressions. Stable sorting requires a tie-breaker, for exampleORDER BY created_at DESC, id DESC, to make pagination reliable. -
Optimistic concurrency control prevents lost updates. Return an
ETagor version, requireIf-Matchon updates, and respond with412 Precondition Failedwhen 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
createdtoconfirmed,preparing,picked_up, anddelivered; reject invalid transitions with409 Conflictrather 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 /doSomethingmisses 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_tableor 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
-
RFC 9110: HTTP Semantics — authoritative definitions for methods, status codes, caching, and conditional requests.
-
RFC 5789: PATCH Method for HTTP — explains partial modification semantics and idempotency considerations.
-
Designing Data-Intensive Applications by Martin Kleppmann — useful depth on consistency, retries, event-driven systems, and distributed failure modes.
Related concepts
- RESTful API And HTTP Service DesignSoftware Engineering Fundamentals
- Object-Oriented Design For Service Code
- Object-Oriented Design, API Design, And TestabilityCoding & Algorithms
- Reliable API Integration And Distributed DesignSystem Design
- API Integration And External Service DesignSystem Design
- Robust Networking, REST, And Concurrency ControlSystem Design