Software Development
API Design Best Practices: What We've Learned Building 20+ APIs
Practical API design lessons from building over 20 production APIs. Covers REST vs GraphQL, versioning, authentication, rate limiting, and documentation.
Giovani Rodríguez6 min read
APIs Are Contracts Between Systems
Over the past several years, we have designed and built more than 20 APIs for clients in fintech, logistics, SaaS, and internal enterprise tools. Every project taught us the same lesson: an API is a contract between systems, and a poorly designed contract creates problems that compound for years.
A well-designed API makes integration easy, reduces support load, and lets your product evolve without breaking the systems that depend on it. A poorly designed one turns every new feature into a negotiation and every integration partner into a frustrated customer.
REST vs GraphQL: Choosing the Right Tool
The REST-versus-GraphQL debate generates more heat than light. The answer depends on context, and we have built production systems with both.
Choose REST when your data model maps cleanly to resources, your consumers are varied and unpredictable (public APIs, third-party integrations), and you want the broadest compatibility. REST is well understood, cache-friendly, and supported by every HTTP client in existence. Most of the APIs we build are RESTful because most business applications deal with clear resource types (users, orders, invoices, products) that map to CRUD operations.
Choose GraphQL when your clients need flexible queries across closely related data, especially when the frontend and backend teams work in the same organization. GraphQL shines in dashboard applications where a single screen might pull data from six different entities. Instead of making six REST calls or building a custom endpoint for every view, the frontend team queries the exact fields it needs.
The mistake we see most often is choosing GraphQL because it sounds modern, then fighting query optimization, N+1 problems, and caching issues that REST handles out of the box. Pick the technology that solves the problem you have.
Versioning: Plan for Change from Day One
Every API will change, so plan for it before you have to scramble. We use URL-based versioning (/v1/, /v2/) on most projects because it is the most explicit option and the easiest for consumers to understand.
Header-based versioning (using Accept headers or custom version headers) is cleaner on paper, but it confuses developers who debug with a browser or curl. Clarity beats elegance when your API consumers include teams you have never met.
Our versioning rules are short. Minor additions, such as new optional fields or new endpoints, go into the current version. Breaking changes, such as removing fields, changing response structures, or altering authentication flows, require a new version. We maintain the previous version for at least six months with clear deprecation notices in both the documentation and the response headers.
Authentication: Match the Pattern to the Use Case
We have implemented every major authentication pattern, and each one fits a specific scenario.
API keys work well for server-to-server communication where the consumer is a known, trusted system. They are easy to implement and easy to rotate. We use them for internal microservice communication and for trusted third-party integrations where the consumer’s server makes the calls.
JWT (JSON Web Tokens) are our default for user-facing applications. The token carries user identity and permissions, so the API can authorize requests without hitting the database on every call. We set short expiration times (15 minutes for access tokens) paired with longer-lived refresh tokens. A JWT that never expires is a security incident waiting to happen.
OAuth 2.0 is the right choice when your API needs to let users authorize third-party applications to act on their behalf. It takes more work to implement, and it became the standard for good reasons. We have built OAuth flows for platforms that supported app marketplaces, and getting OAuth right up front saved those teams far more trouble than a custom delegation system would have caused.
Rate Limiting: Protect Your API and Your Customers
Every API we ship includes rate limiting, internal ones included. Rate limits protect your infrastructure from abuse, stop one misbehaving client from degrading service for everyone else, and give you a natural mechanism for tiered pricing.
We return rate limit information in response headers on every request: X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset. Consumers can then monitor their own usage and back off before they hit the wall. An API that silently drops requests without telling the consumer why creates bugs for its consumers.
For implementation, we use sliding window counters backed by Redis. Fixed windows create thundering herd problems at window boundaries. Token bucket algorithms suit bursty traffic. Your traffic profile decides the right choice, but sliding windows make a solid default.
Error Handling: Be Specific and Consistent
Vague error messages frustrate API consumers more than anything else. We use the same error response structure across every API we build:
The response includes an HTTP status code that follows standard conventions (400 for bad requests, 401 for authentication failures, 403 for authorization failures, 404 for missing resources, 422 for validation errors, 429 for rate limits, 500 for server errors). The body includes a machine-readable error code, a human-readable message, and a details array for validation errors that points to specific fields.
We never expose stack traces or internal implementation details in production error responses. They are a security risk. We do include a request ID in every error response, so when a consumer contacts support, we can trace the exact request through our logs.
Documentation: Start With OpenAPI, Then Go Further
We generate our API documentation from OpenAPI (Swagger) specifications and treat the generated docs as a first draft. Raw schema documentation tells you what the API accepts. It does not tell you how to use it.
Every API we deliver includes a getting-started guide that takes a developer from zero to their first successful request in under five minutes. It includes workflow guides that show how endpoints combine to accomplish real tasks, plus example requests and responses for every endpoint alongside the schema definitions.
Good API documentation answers “how do I do X?” as well as “what does endpoint Y accept?” In our projects, investing in documentation quality has reduced support requests by 40-60% compared to shipping schema docs alone.
Pagination: Choose a Strategy and Stick With It
For most APIs, we use cursor-based pagination. Offset-based pagination (?page=2&limit=20) is simpler to implement but breaks when someone inserts or deletes data between requests, and the consumer sees duplicates or misses records. Cursor-based pagination uses a pointer to the last item returned, which keeps results consistent regardless of changes to the underlying data.
We include pagination metadata in every response: total count (when feasible), next cursor, and a boolean indicating whether more results exist. For endpoints with large datasets where total count is expensive to compute, we omit it and rely on the has_more flag.
Conclusion
In API design, the decisions you make in the first week determine how much pain you feel for the next several years. We follow explicit versioning, context-appropriate authentication, consistent error handling, honest documentation, and stable pagination because real projects showed us the cost of getting each one wrong and the payoff of getting it right.
If you are planning an API and want to get the foundation right from the start, reach out to us. We would rather help you design it well the first time than refactor it later.
- #API
- #REST
- #GraphQL
- #Backend
- #Architecture


