High Level Design

API Design

What makes a good API — goals of scalability, extensibility, and ease of use, plus REST best practices and common design patterns.

August 10, 2026

An API (Application Programming Interface) is a software contract that defines the expectations and interactions between external users (clients) and a piece of code (service). It specifies:

  • API name
  • Accepted parameters
  • Response structure
  • Error messages and codes

Goals of Good API Design#

1. Scalability#

  • Supports increased load (traffic, data, users) with minimal changes
  • Follows standards that allow horizontal scaling (e.g., RESTful resource modeling)

2. Extensibility#

Easy to add new features or modify behavior without breaking existing consumers. Achieved by:

  • Versioning (/v1, /v2)
  • Optional parameters
  • Backward-compatible responses

3. Ease of Use#

  • Clear, intuitive naming and structure
  • Helpful and consistent error messages
  • Good documentation

REST API Principles#

REST (Representational State Transfer) is a set of architectural constraints for building web APIs:

  • Stateless — each request contains all the information needed to process it
  • Resource-based — endpoints represent resources (/users, /orders)
  • Standard HTTP methods — GET, POST, PUT, PATCH, DELETE
  • Consistent error codes — use standard HTTP status codes

HTTP Method Semantics#

MethodOperationIdempotent?
GETRead resource✅ Yes
POSTCreate resource❌ No
PUTReplace resource✅ Yes
PATCHPartial update✅ Yes
DELETEDelete resource✅ Yes

Common Status Codes#

CodeMeaning
200OK
201Created
400Bad Request
401Unauthorized
403Forbidden
404Not Found
429Too Many Requests (rate limit)
500Internal Server Error

API Versioning Strategies#

StrategyExampleProsCons
URL path/v1/usersEasy to understandURL pollution
Query param/users?version=1Non-breakingLess clean
HeaderAccept: application/vnd.api.v1+jsonClean URLsHidden from browser

Error Response Design#

Consistent error responses help clients handle failures gracefully:

json
{
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "You have exceeded your request quota.",
    "retry_after": 30
  }
}

Pagination Patterns#

PatternDescriptionUse Case
Offset-based?page=2&limit=20Simple; good for small datasets
Cursor-based?after=eyJpZCI6MTB9Consistent for large/changing datasets
Keyset?after_id=1000Efficient for database queries