Back to the journalNOTES BY FAJAR
Software Engineering3 min read

API Design: Design-First vs Code-First

Compare writing an API contract before implementation with deriving the contract from code.

In this article 5 sections

API design affects how teams build, document, and consume a software system. Two common approaches are design first and code first. With design first, the team agrees on the contract before implementation. With code first, the implementation defines the contract.

Design first: architecture before implementation

Design first puts an API specification ahead of the implementation. The team describes the endpoints, payloads, and rules before writing the service code. OpenAPI or Swagger can provide a shared format for that description.

This order gives the team a structured specification, documentation that precedes code, and a chance to validate the design before development starts. It can make communication clearer, keep the API consistent, and give multiple teams a contract to review. The cost is an initially slower process and a need for people who can make those design decisions.

Code first: speed through implementation

With code first, the API takes shape as the team writes the implementation. The team can start coding immediately, adjust the behavior as requirements change, and focus on working functionality.

That approach can shorten the first development cycle and fit a small team, a quick prototype, or a project whose requirements are still unclear. Without a separate design step, endpoints can become inconsistent. Documentation can also fall behind the code, which makes later API changes harder to coordinate.

Choosing between the approaches

Design first fits enterprise projects, complex systems, larger teams, and situations where detailed documentation is part of the deliverable. Code first fits a quick prototype, a limited scope, a small team that communicates closely, or requirements that are changing quickly.

The choice should follow the project's complexity, team structure, business needs, and how clearly the requirements are understood. A team can also combine the approaches. It can agree on the main contract first and use implementation work to resolve the remaining details.

No single method fits every project. Start with the amount of coordination the project requires. When several clients depend on the same contract, writing and reviewing the API design before implementation usually prevents more rework. When the problem is still being explored, a small code first slice can expose the missing requirements quickly.

What I have seen in practice

From my professional experience developing APIs over several years, most complex projects I worked on used design first. As the technology system grows, consistency and documentation become harder to recover after the fact.

At the financial technology startup where I work now, my team uses design first because we support a mobile application. Consistent API design matters to both sides, and our API documentation acts as the source of truth. We treat that document as a contract that the mobile client and the service should follow.

My previous team used code first, even though it also had a mobile application. The contract lived in the code and in direct conversations between teams rather than in an API document. Development felt fast and flexible, but we often had consistency problems. Decisions made during implementation were easy to forget, so we eventually needed API documentation as a reference anyway.

The tradeoff

My advice is not to lock a project into one methodology. Technology and requirements change, so the API design process should change with them. Revisit the choice when the team grows, a new client appears, or the cost of undocumented decisions becomes visible.

An API needs a clear contract and a correct implementation. Choose the approach that gives the people using the API enough confidence to build against it.

FILED UNDER

THANKS FOR READING

Did this resonate?

A reaction or a conversation is always welcome.

Loading reactions…

Pass it along

Loading comments...

Related posts

All writing