Versionamento de APIs e Compatibilidade Retroativa
Aprenda estratégias para evoluir APIs sem quebrar clientes existentes, incluindo esquemas de versionamento e regras de compatibilidade.
Versionamento de APIs e Compatibilidade Retroativa é uma aula grátis de System Design Basics for Backend Developers no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de System Design Basics for Backend Developers, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de System Design Basics for Backend Developers inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Why APIs Must Evolve Carefully
Once an API has clients, you cannot freely change it. Renaming a field or removing an endpoint can break every consumer. Versioning lets you evolve the API while existing clients keep working.
Breaking vs Non-Breaking Changes
Know the difference:
- Non-breaking: adding a new optional field, adding a new endpoint
- Breaking: removing a field, renaming a field, changing a type, making an optional field required
Non-breaking changes can ship without a new version; breaking ones cannot.
URI Versioning
The most visible scheme puts the version in the path. It is simple and cache-friendly, and clients can clearly see which version they call.
GET /v1/users/42
GET /v2/users/42Header Versioning
Alternatively, clients request a version via a header. This keeps URIs clean and treats the version as part of content negotiation.
GET /users/42
Accept: application/vnd.myapp.v2+jsonQuery Parameter Versioning
A lighter approach uses a query parameter, e.g. ?version=2. It is easy to test in a browser but mixes versioning with regular parameters and can complicate caching.
GET /users/42?version=2Semantic Versioning
SemVer (MAJOR.MINOR.PATCH) communicates intent:
- MAJOR: breaking changes
- MINOR: new backward-compatible features
- PATCH: backward-compatible fixes
For public HTTP APIs, the MAJOR number usually maps to the URI version.
Additive Change Discipline
The cheapest versioning is not needing a new version. Follow the additive rule: only add, never remove or rename. Clients ignore unknown fields, so adding is safe.
{
"id": 42,
"name": "Ada",
"email": "ada@x.com"
}
// Later, safely add:
{
"id": 42,
"name": "Ada",
"email": "ada@x.com",
"created_at": "2026-01-01"
}Deprecation, Not Deletion
When you must retire something, deprecate first. Mark it in docs, send a Deprecation or Sunset header, and give clients a clear timeline before removal.
HTTP/1.1 200 OK
Deprecation: true
Sunset: Wed, 31 Dec 2026 23:59:59 GMT
Link: </v2/users>; rel="successor-version"Versioning gRPC and GraphQL
It is not just REST. In gRPC, never reuse or renumber protobuf field tags — that breaks the wire format. In GraphQL, the convention is no versions at all: add fields and use the @deprecated directive on old ones.
Supporting Multiple Versions
Running several versions at once has a cost. Strategies include translating old requests to the new internal model, or routing versions to different handlers. Limit how many versions you support and sunset old ones on schedule.
Designing for Change Up Front
Reduce future pain by designing for evolution: prefer objects over bare values so you can add fields, avoid leaking internal enums, and document a clear compatibility contract from day one.
Quick Check
Test your understanding of API versioning.
Recap
You learned how to evolve APIs safely:
- Distinguish breaking from non-breaking changes
- URI, header, and query parameter versioning schemes
- SemVer and the additive-change discipline
- Deprecate with Sunset headers before deleting
- gRPC tag stability and GraphQL's deprecation approach
Perguntas Frequentes
A aula “Versionamento de APIs e Compatibilidade Retroativa” é grátis?
Sim — o texto completo de “Versionamento de APIs e Compatibilidade Retroativa” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de System Design Basics for Backend Developers, atualize para CoddyKit PRO. O curso de System Design Basics for Backend Developers inclui 4 aulas no total.
O que vou aprender em “Versionamento de APIs e Compatibilidade Retroativa”?
Aprenda estratégias para evoluir APIs sem quebrar clientes existentes, incluindo esquemas de versionamento e regras de compatibilidade. Você pratica System Design Basics for Backend Developers com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar System Design Basics for Backend Developers?
Nenhuma experiência prévia é necessária. System Design Basics for Backend Developers no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Versionamento de APIs e Compatibilidade Retroativa”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de System Design Basics for Backend Developers?
Sim. Cada aula de System Design Basics for Backend Developers inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Princípios de design de APIs RESTful
- GraphQL e gRPC
- Filas de mensagens e orientado a eventos
- Versionamento de APIs e Compatibilidade Retroativa