wasAsked.

How would you version a public Spring Boot API without breaking existing web and mobile clients?

PhonePe · Full Stack Developer · 3-4-years · technical

Published

Year not specified · Java, Spring Boot, Software Engineering

Community answers

Posted by wasAsked editorial collection

Versioning should be the last resort; first design for backward-compatible evolution. Compatible changes (no new version needed) - Adding optional request fields or new response fields, new endpoints, and new optional query parameters. - Clients must ignore unknown fields: Jackson's FAIL_ON_UNKNOWN_PROPERTIES is false by default in Spring Boot, and mobile clients should be tolerant too. - Avoid changing the meaning of existing fields, renaming fields, making optional fields required, or tightening validation without warning. When a breaking change is required — choose a scheme - URI versioning (/api/v1/orders, /api/v2/orders): explicit, cache-friendly, and simple for mobile apps and partners. The most common choice. - Header or media type versioning (Accept: application/vnd.company.order.v2+json, or a custom header): clean URLs but harder to test and cache. - Spring Framework 7 and Spring Boot 4 add first-class API versioning support (version attributes on request mappings and configurable version resolution); on earlier versions, implement with separate controllers or request mapping conditions. Implementation practices - Keep business logic shared; put version differences in the web layer (separate DTOs and mappers per version). - Generate one OpenAPI document per version with springdoc groups. - Contract tests for each supported version so v2 changes do not break v1. Mobile-specific concerns - Old app versions stay installed for months. Track client versions with a header (X-App-Version), monitor usage per API version, and implement a minimum-supported-version check that prompts users to upgrade. - Use feature flags and server-driven configuration to adapt behaviour without new app releases. Deprecation process - Announce in documentation and changelogs; send Deprecation and Sunset headers (RFC 8594) with a link to migration guides. - Monitor traffic per version and per client; contact major API consumers. - Remove a version only after usage drops and the published sunset date passes (for example 6–12 months for public APIs). Events and messages - Apply the same thinking to Kafka event schemas: a schema registry with backward compatibility rules, and new event versions when semantics change.

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics