API Versioning, Deprecation and Backward Compatibility Questions
Evolving an API without breaking existing consumers: versioning schemes (URI, header, media type, semantic versioning), classifying breaking versus non-breaking changes including behavioural ones such as defaults and error text, deprecation and sunset policy and timelines (including accelerated retirement), running multiple versions concurrently, and planning consumer migrations at scale including SDK, partner, mobile and long-tail client impact. Also covers finding who still calls an old version, catching accidental breaks with contract checks in CI, expand-then-contract evolution of fields and stored data, gradual rollout with per-version monitoring, and compatibility between independently deployed services, streams and libraries. Covers compatibility guarantees across REST, GraphQL and gRPC consumers. Excludes general API surface design, payload and OpenAPI schema design, protobuf field-level mechanics, writing the notices themselves, rate limiting, gateways and database schema migration.
Your public developer API has many external customers. How do you weigh strict backward compatibility and long deprecation windows against faster iteration with more frequent breaking changes? Propose a policy that balances developer experience, business agility and engineering velocity.
Sample Answer
The idea in plain words
A major version is a release of the API that is allowed to contain breaking changes (v1, v2, v3); a minor change is an additive one that keeps the same major. Strict backward compatibility (old integrations keep working unchanged) protects consumers' engineering time and your reputation. Fast iteration (changing the contract whenever the product needs it) protects your own speed. They only conflict when every change is treated as the same kind of change. The policy that balances them separates the cheap changes (additive, allowed any time) from the expensive ones (breaking, batched, announced, and supported for a fixed window), and puts a number on how often you may ask consumers to migrate.
Step 1: sort changes into three classes
- Additive and non-breaking: new optional response fields, new endpoints, new optional request parameters. Ship any time, no notice beyond the changelog. Consumers must be told in the docs to ignore unknown fields (the tolerant reader rule: clients read the fields they need and ignore the rest).
- Breaking: removing or renaming a field, changing a type, adding a required request field, tightening validation, changing the meaning of a value, adding a value to an enum that clients switch over. These need a new major version.
- Preview or beta surface: endpoints explicitly labelled as unstable, with their own shorter rules. This is where fast iteration lives.
Step 2: choose two numbers that set the trade-off
Let C be the interval between major versions (cadence) and W be the support window, how long the previous major keeps working after its successor is generally available (GA: open to all customers, not a preview). Because several majors can be live together, the most majors you ever support at once is 1 + ceil(W / C), where ceil rounds up to a whole number.
A major that stops at the same month its successor's successor is released is counted as already gone. Worked comparison, each row counted by listing the release months and the month each major stops (successor release plus W):
| C (months between majors) | W (months of support after successor) | Majors live at once, worst case |
|---|---|---|
| 12 | 18 | 3 |
| 18 | 12 | 2 |
| 12 | 12 | 2 |
| 24 | 12 | 2 |
Why the first row is 3: major N is released at month 0, N+1 at 12, N+2 at 24. N stays supported until 12 + 18 = 30, so from month 24 to 30 all three run together, for 6 of every 12 months. In the second row, N is released at 0, N+1 at 18, N+2 at 36, and N is supported until 18 + 12 = 30, so it is gone before N+2 appears, which gives at most 2. Row 3: N is released at 0, N+1 at 12, N+2 at 24, and N stops at 12 + 12 = 24, the month N+2 appears, so only two majors are ever live at once (1 + ceil(12 / 12) = 2). Row 4: N at 0, N+1 at 24, N+2 at 48, and N stops at 24 + 12 = 36, long before N+2, so again at most two (1 + ceil(12 / 24) = 1 + 1 = 2).
Step 3: the policy I would propose (assumed numbers)
- Additive changes: any time, announced in the changelog.
- Breaking changes: only in a new major version, at most one new major every 18 months (C = 18), batched so consumers migrate once, not repeatedly.
- Support window: the previous major runs for at least 12 months after the new one is generally available (W = 12). The sunset date is stated on the first day of that window using the
Sunsetheader (RFC 8594, a response header giving the date the version stops working) with aDeprecationheader (RFC 9745) on responses. Result: at most two majors live (second row of the table). - Beta surface: marked unstable in docs and responses, breaking changes with 30 days notice, no support commitment beyond that; a surface leaves beta only after it has met a stated stability bar (a written test it must pass before it counts as stable, for example no breaking change in two consecutive releases).
- Exceptions: security, legal or upstream-dependency triggers may shorten the window under a written decision by the API owner, engineering lead and the function that owns the trigger.
- Governance: every breaking change needs a short proposal listing affected consumers from telemetry. A quarterly review looks at how many majors were live, how many support tickets each migration cost, and how long the tail took to clear.
How this serves the three goals
- Developer experience: a predictable rule (additive any time, breaking at most every 18 months, 12 months notice) lets consumers plan; they are never surprised by a Tuesday change.
- Business agility: new capability ships continuously as additive changes and beta endpoints; only changes that really break wait for the next major, and the roadmap can plan for the next major's date.
- Engineering velocity: capping live majors at two limits the cost of fixing a bug in several code paths, running several test suites and carrying old behaviour. If measured maintenance cost is too high, lengthen C rather than shorten W, because lengthening C stretches the interval between migrations for consumers and lowers concurrent versions.
What would flip the choice
- Consumers are few and all internal: shorten W (even to a few months) because you can coordinate directly.
- Consumers are regulated or embedded devices that upgrade rarely: lengthen W to 24 months, and accept 1 + ceil(24 / 18) = 3 live majors, or lengthen C to 24 so that 1 + ceil(24 / 24) = 2.
- Telemetry at the sunset date shows a large share of traffic still on the old major: extend by a fixed step, but only with a named customer list, not silently.
Common mistakes
- Treating "breaking" as a product decision instead of a defined list, so teams argue per change.
- Setting a window without computing how many majors that implies at once.
- Offering the long window to everyone when only a handful of consumers need it, instead of per-customer extensions.
- Putting fast-moving features into the stable surface rather than a labelled beta surface.
How would you manage API evolution for a platform with thousands of third-party clients so you can keep innovating while minimising breakage? Think about governance, tooling, deprecation, compatibility checks, SDKs, migration telemetry and what motivates clients to upgrade.
Sample Answer
The idea in plain words
With thousands of third-party clients (the consumers: other companies' programs that call your API), you cannot coordinate a release with each one. So evolution at this scale is a programme with four parts: rules for what counts as a breaking change, automated checks that enforce the rules before release, a published deprecation process with notice periods, and measured migration with incentives. The goal is to make the safe path the default: additive changes ship continuously and need no coordination, while the rare breaking change goes through a slow, visible, measured process.
A breaking change is any change that makes a previously correct client fail or misbehave. Deprecation means "still works, scheduled for removal, please migrate". Sunset is the date the old behaviour stops. An SDK (software development kit) is the client library you publish so consumers do not hand-write HTTP calls.
The method, in the order I would build it
1. Governance: who decides, and what the rules are
- A written compatibility policy the whole company can read: what is guaranteed (response fields are never removed or retyped within a major version, new enum values may appear, new optional fields may appear), what is not (field order, undocumented behaviour), and the minimum notice period for removal.
- A small API review group (a few senior engineers plus a product manager) that approves any change flagged breaking. Teams own their APIs; the group owns the exceptions and the policy, not every change.
- A named owner per endpoint in a registry, so a deprecation always has someone accountable.
As the product manager, the decision I own is the cost trade-off: every breaking change spends consumer trust, so it needs a stated reason (security, legal, an unfixable design flaw), not "the new design is nicer".
2. Tooling: catch breakage before release
- Contract diff in CI (continuous integration, the automated build and test pipeline): compare the proposed API description with the last released one and fail the build on removed fields, retyped fields, new required inputs and tightened validation. Tools in this category exist for OpenAPI, GraphQL schemas and protobuf.
- Consumer-driven contract tests: key partners publish the requests and responses they depend on, and the provider's pipeline replays them against each build. This catches behaviour a schema diff cannot see.
- A compatibility test suite per SDK: each released SDK version runs against the candidate server in CI.
- Feature flags (runtime switches that turn behaviour on or off without a deploy) and canary releases (send a small share of traffic to the new build first, for example 1 percent, then 10 percent, then all, watching error rate by consumer at each step). A canary limits the damage of a break that slips through; a flag is the instant rollback.
3. Deprecation as a process with a calendar
Every deprecation follows the same template: announce, mark in machine-readable form, warn at runtime, brown out, sunset. A brown out is a short, announced window in which the old version deliberately returns errors, so callers who ignore email find out while the harm is small; the sunset is the date the old version is switched off for good. A sample timeline follows in the worked example. The runtime signals use real standards: the Deprecation response header (RFC 9745) and the Sunset response header (RFC 8594), plus a Link header pointing to the migration guide.
4. Migration telemetry
You cannot manage what you cannot see. Log, per API key and per SDK version: which version or endpoint was called, which deprecated features were used, and the error rate. From that, build a dashboard of "keys still on the old path" and a contact list ranked by traffic and by revenue. Keep a note of what this cannot show: a response field a client reads leaves no trace on the server, so SDK-side telemetry, consumer contract tests and direct partner contact fill that gap.
5. What motivates clients to upgrade
Clients migrate when it is cheap, when it is worth it, or when they have no choice, in that order of preference:
- Cheap: a migration guide, a codemod (a script that rewrites a consumer's source code automatically) or SDK upgrade that does most of the work, a test environment for consumers, and an SDK that handles the change so the consumer only bumps a version number.
- Worth it: the new version carries something they want (a feature, better performance, higher rate limits). Do not ship new features to the old version.
- No choice: a dated sunset, brownouts, and direct outreach to the largest consumers. Pressure is the last lever, not the first.
Worked example: a sample deprecation timeline
Assumptions, all illustrative: 4,000 active API keys; the old version is called v1 and the new one v2; the notice period is 52 weeks (364 days) for external consumers. Announcement on Monday 2027-03-01.
| Week | Date (Monday) | Event | Keys on v1 (trailing 30 days) | Share of 4,000 |
|---|---|---|---|---|
| 0 | 2027-03-01 | Announce, publish guide, add Deprecation and Sunset headers on v1, email owners | 4,000 | 4000 / 4000 = 100% |
| 13 | 2027-05-31 | Warning banner in the developer portal; v2 only gets new features | 2,900 | 2900 / 4000 = 72.5% |
| 26 | 2027-08-30 | Personal outreach to the top 50 keys by traffic still on v1 | 1,700 | 1700 / 4000 = 42.5% |
| 39 | 2027-11-29 | Second email; test-environment v2 load test offered | 800 | 800 / 4000 = 20.0% |
| 44, 48, 50 | 2028-01-03, 2028-01-31, 2028-02-14 | Brownouts: v1 returns an error for a short, announced window | 260 at week 48 | 260 / 4000 = 6.5% |
| 52 | 2028-02-28 | Sunset | 40 | 40 / 4000 = 1.0% |
A key counts as on v1 if it called v1 at least once in the trailing 30 days (the 30 days before the date shown), so keys that went quiet do not inflate the count. The top 50 keys by traffic are tracked separately because a few large consumers carry far more requests than hundreds of small ones: a share of keys alone can look healthy while most of the traffic is still on v1.
The sunset rule I would write down: sunset on the later of (announcement plus 364 days) and (the first date at which v1 keys are at most 1.0 percent of active keys and none of the top 50 by traffic remain). Announcement plus 364 days is 2028-02-28, and the table shows 1.0 percent on that date, so the rule is met exactly on the notice date, assuming for this illustration that all of the top 50 have moved by then, and the sunset goes ahead. Had the week-52 figure been 60 keys (1.5 percent), the date would slip until the usage condition held, and the remaining keys would get a tracked, expiring exception rather than an open-ended one.
Illustrative response headers on a v1 call during the notice period (the values match the table: 1803859200 is 2027-03-01 00:00:00 UTC as a Unix timestamp in seconds, and the sunset is the week-52 Monday):
HTTP/1.1 200 OK
Content-Type: application/json
Deprecation: @1803859200
Sunset: Mon, 28 Feb 2028 00:00:00 GMT
Link: <https://developers.example.com/migrate-v1-v2>; rel="deprecation"; type="text/html"
Deprecation: @1803859200 is a structured-field date (a date format from the HTTP structured field values specification: an @ followed by whole seconds since 1970-01-01 00:00:00 UTC, called Unix time; RFC 9745 uses it) meaning "deprecated since this instant". To convert by hand: 1803859200 / 86400 seconds per day = 20,878 whole days after 1970-01-01, and that day is 2027-03-01. Sunset is an HTTP-date (RFC 8594) giving the removal time. The Link header with rel="deprecation" points to the human guide.
Read the sunset rule as two conditions that must both hold: (A) at least 364 days have passed since the announcement, and (B) v1 keys are at most 1.0 percent of active keys and none of the top 50 remain. Sunset is the first date on which both are true. The program below converts the timestamp and checks both conditions against the table.
from datetime import datetime, timedelta, timezone
announce = datetime(2027, 3, 1, tzinfo=timezone.utc)
ts = int(announce.timestamp())
print("Deprecation: @" + str(ts), "=", ts // 86400, "whole days after 1970-01-01 plus", ts % 86400, "seconds")
print("back to a date:", datetime.fromtimestamp(ts, timezone.utc).isoformat())
sunset = announce + timedelta(days=364)
print("Sunset:", sunset.strftime("%a, %d %b %Y %H:%M:%S GMT"))
active_keys = 4000
for week, keys in [(0, 4000), (13, 2900), (26, 1700), (39, 800), (48, 260), (52, 40)]:
day = (announce + timedelta(weeks=week)).date()
print(f"week {week:2} {day} keys on v1: {keys:4} = {100 * keys / active_keys:.1f} percent")
at_sunset = 40
print("usage condition (at most 1.0 percent):", at_sunset / active_keys <= 0.01)
print("date condition (announcement + 364 days):", sunset.date())
Output:
Deprecation: @1803859200 = 20878 whole days after 1970-01-01 plus 0 seconds
back to a date: 2027-03-01T00:00:00+00:00
Sunset: Mon, 28 Feb 2028 00:00:00 GMT
week 0 2027-03-01 keys on v1: 4000 = 100.0 percent
week 13 2027-05-31 keys on v1: 2900 = 72.5 percent
week 26 2027-08-30 keys on v1: 1700 = 42.5 percent
week 39 2027-11-29 keys on v1: 800 = 20.0 percent
week 48 2028-01-31 keys on v1: 260 = 6.5 percent
week 52 2028-02-28 keys on v1: 40 = 1.0 percent
usage condition (at most 1.0 percent): True
date condition (announcement + 364 days): 2028-02-28
Read-out: the first two lines convert the timestamp both ways, and the third is the Sunset value. Condition A is met on 2028-02-28 (announcement plus 364 days). Condition B is met by week 52, where 40 / 4,000 = 1.0 percent is at most 1.0 percent, and the top 50 are assumed gone. Both are true on 2028-02-28, so the sunset goes ahead on that date with nothing to spare; at 60 keys (1.5 percent) condition B would fail and the date would slip.
This timeline is an illustration of the shape (long notice, escalating steps, measured thresholds). A real process must also handle consumers who have no active maintainer, mobile apps that update slowly, regulated customers with change freezes, and contractual notice terms.
Trade-offs and pitfalls
- Versioning the whole API for every change multiplies the versions you support. Prefer additive evolution inside a major version, and cut a new major version only for changes that cannot be made additively.
- Long support windows cost engineering time: each concurrent version is another set of tests, security patches and documentation. Set the maximum number of concurrently supported majors in the policy (for example two) so the cost is bounded.
- Pressure without help creates churn: brownouts without a migration path produce angry support tickets, not migrations.
- The silent consumers are the risk: the biggest breakage comes from keys that never read email. Brownouts are how you find them while the damage is still small.
- Announced dates are promises: moving a sunset later is cheap once; doing it repeatedly teaches consumers that dates are negotiable.
Common mistakes
- Treating deprecation as an email rather than a process with machine-readable signals and measurement.
- Measuring only server traffic and concluding a response field is unused.
- Giving every consumer the same deadline regardless of size, instead of tiered handling (different treatment by consumer size) for the top consumers.
- Announcing a sunset with no migration tooling or test environment.
Running the code
Paste the program into a file and run it with Python 3.12; it needs no extra packages and prints exactly the output shown.
Two teams disagree on how to version a public API: one wants the version in the URL, the other wants it in a request header. Build a short evaluation rubric to settle it, say which you would choose for your situation, and explain how you would announce the decision and its migration timeline to external integrators.
Sample Answer
The idea in plain words
The URL-versus-header argument is really an argument about which costs each team is willing to carry. A URI version puts the number in the path (/v2/orders); every request is self-describing, caches and routers see it without extra rules, and it is easy to test with a browser or curl. A header version (a custom header such as API-Version: 2, or a versioned media type, a vendor-specific content type that carries the version, such as Accept: application/vnd.example.v2+json) keeps the URL stable as the name of the resource, which is purer, but the version is invisible in logs, links and caches unless you make it visible. A rubric turns the disagreement into explicit weights and scores that both teams can argue about.
Questions I ask before choosing
- How fast can clients update? Server-side integrations can move in weeks; mobile apps and partners that ship on a fixed calendar (release trains) take months. This sets the notice period and whether concurrent versions are needed.
- What do partner contracts promise? A contract with a 12-month notice clause fixes the minimum timeline no matter which scheme wins.
- What can we see? If we cannot count callers per version (gateway logs, API-key telemetry), neither scheme lets us retire anything safely.
- Who calls us? Browsers, low-code tools and scripts favour a visible URL; sophisticated SDK clients cope with headers.
- Is there a CDN or cache in front? A CDN (content delivery network) is a set of cache servers near users. It determines how much the scheme costs at the edge, because a cache compares the URL by default and needs an extra rule (a
Varyheader) to also compare a version header.
The evaluation rubric
Assumed situation for the scoring: a public partner API with about 300 integrators, a CDN in front, a mix of SDK users and hand-written scripts, a 12-month contractual notice clause for breaking changes. Weights sum to 100. Scores are judgements from 1 (poor) to 5 (strong), assumptions rather than measurements.
| Criterion | Weight | URL | Header |
|---|---|---|---|
| Cacheability at the CDN | 15 | 5 | 3 |
| Routing and gateway simplicity | 15 | 5 | 3 |
| Debuggability (curl, browser, logs) | 15 | 5 | 3 |
| Discoverability in docs and analytics | 15 | 5 | 3 |
| Fit for versioning one resource independently | 10 | 2 | 4 |
| Safe behaviour when the client omits the version | 10 | 5 | 2 |
| Migration cost for existing clients | 10 | 3 | 4 |
| Alignment with "a URL names a resource" | 10 | 2 | 4 |
What the rows measure. Cacheability: how easily a CDN keeps separate copies per version (the URL is the cache key by default, so URL scores 5; a header needs a Vary rule at every cache, so 3). Routing: how simply a gateway or router picks the right deployment (a path prefix match versus parsing a header). Debuggability and discoverability: whether the version is visible in curl, a browser, logs and analytics. Fit for versioning one resource independently: whether /orders can move to a new version while /customers stays (a header handles that more naturally, a path major moves everything). Safe behaviour when the client omits the version: with a path there is no way to omit it, while a missing header must fall back to some default. Migration cost: how much existing clients must change. Alignment with "a URL names a resource": whether the URL stays the permanent name of the thing.
Weighted score out of 100 = sum of (weight x score) divided by 5. Why 5: the weights sum to 100, so an option scoring 5 on every row would total 100 x 5 = 500, and dividing by 5 turns that perfect 500 into 100.
- URL: 15x5 + 15x5 + 15x5 + 15x5 + 10x2 + 10x5 + 10x3 + 10x2 = 75 + 75 + 75 + 75 + 20 + 50 + 30 + 20 = 420. 420 / 5 = 84.
- Header: 15x3 + 15x3 + 15x3 + 15x3 + 10x4 + 10x2 + 10x4 + 10x4 = 45 + 45 + 45 + 45 + 40 + 20 + 40 + 40 = 320. 320 / 5 = 64.
Sensitivity: remove the cacheability row (suppose no CDN). The remaining weights sum to 100 - 15 = 85, so a perfect score would be 85 x 5 = 425. URL: 420 - 75 = 345 of 425, which is 345 / 425 x 100 = 81.2 out of 100. Header: 320 - 45 = 275 of 425, which is 275 / 425 x 100 = 64.7. Remove cacheability and routing together (70 weight left, perfect score 350): URL = 270 / 350 x 100 = 77.1 and header = 230 / 350 x 100 = 65.7. The URL scheme still leads in this situation, so the decision is not an artefact of the CDN assumption.
What I would choose, and what would flip it
Choose the major version in the URL (/v1/, /v2/) for breaking changes only, with additive changes shipped inside a version without a new number. Reasons: partners are many and varied, a CDN sits in front, and a missing header silently pinning clients to some default is a real hazard. This follows the weights above: the four criteria worth 15 each all favour the URL.
It flips toward headers or media types when: there is no CDN and no hand-written clients, versioning of individual resources matters more than whole-API versions, or the platform is a hypermedia API (responses carry links telling the client what it can do next, so representations are already negotiated by media type).
Three alternatives and their trade-offs
| Approach | What it is | Strength | Cost |
|---|---|---|---|
| Major versions side by side | /v1 and /v2 run together | Clear contract, easy to route and measure | Two code paths to run, test and secure until sunset |
| In-place evolution with deprecation windows | One version; add, deprecate, remove per field with notice | No migration event for additive changes | Every removal needs its own notice and usage proof; hard for sweeping changes |
| Adapters | One internal model; adapters (small translation layers at the edge) present old shapes | Old clients keep working while the core moves on | Adapter bugs, hidden coupling, and a permanent layer if never retired |
In practice these combine: in-place evolution for small changes, a new major version for a real break, and adapters to run the old major cheaply during its notice period.
Announcing the decision and the timeline
The dates here are assumptions that satisfy the assumed 12-month clause. Announce Tuesday 2027-06-01. Version 2 reaches general availability Wednesday 2027-09-01 (92 days after the announcement). Version 1 returns Deprecation and Sunset headers from that date (RFC 9745, RFC 8594) with a sunset of Thursday 2028-06-01, which is 366 days after the announcement (the span includes 2028-02-29) and 274 days after general availability. Checkpoints on the way: a reminder to every caller still on v1 on 2028-03-01 (92 days before sunset), a test brownout (a short announced window in which v1 is made to fail on purpose so forgotten callers notice) on 2028-05-01 (31 days before) and a final warning on 2028-05-15 (17 days before).
What the announcement carries, in the channels integrators actually read:
- the decision and the rubric result in two sentences, the date table, and the migration guide;
- a per-integrator message listing which of their keys still call v1 and how many calls per day;
- a changelog entry, a status-page notice, and headers on the responses themselves;
- a named contact and a sandbox with v2 enabled so teams can test before they commit.
Common mistakes
- Debating taste instead of scoring criteria against the real consumer base.
- Letting a missing header default to the oldest version forever.
- Picking a scheme without telemetry to count callers per version.
- Announcing a date shorter than the contract notice.
A backwards-incompatible API change is planned, your clients use SDKs in several languages, and you do not know when they will upgrade. How do you plan the deprecation and migration under that uncertainty: dual running, SDK updates, communication, telemetry and enforcement milestones?
Sample Answer
The idea in plain words
If you do not know when clients will upgrade, do not plan on a date; plan on evidence. Run the old and new contract side by side (dual running: one deployment serves both the old and the new contract at once), make the SDKs (software development kits, the client libraries your customers install) carry as much of the change as possible, measure who is still on the old path from telemetry, and tie each enforcement step to a measured threshold as well as a calendar date. Customers who never upgrade on their own are the reason the last step must be an enforcement step, not another reminder.
The plan, in the order I would do it
- Make the old path visible. Before announcing anything, make every SDK identify itself, and ask every raw HTTP client (a program that calls the API directly, with no SDK) to do the same. The
User-Agentheader (RFC 9110) carries product tokens such asacme-sdk-python/3.4.1; an additional custom header with the SDK language and version is also reasonable. Log per request: API key, endpoint, contract version, SDK language and version. Without this you are guessing. - Ship the new contract as v2 next to v1. Both are served by the same deployment. Version in the URL or in a media type (the format name clients send in the
Acceptheader, such asapplication/vnd.example.v2+json), whichever you already use; the choice matters less than keeping the two contracts independent. - Let the SDKs hide the break. Release a new major SDK version in each language that speaks v2. Also release a minor version of the old SDK major that keeps the same public method signatures and calls v2 internally with an adapter, where the change is small enough to hide. Customers on old SDKs then get a one-line dependency bump instead of a rewrite. Where the break cannot be hidden (a method's meaning changes), the old SDK major gets deprecation warnings at call time that name the replacement.
- Announce with signals on every channel. Responses on v1 carry
Deprecation(RFC 9745) andSunset(RFC 8594) headers and aLinkheader withrel="deprecation"; SDKs print a once-per-process warning that includes the date; email and dashboard banners go to key owners, not to a generic list. - Set milestones gated by usage. A date is a promise to consumers; a threshold decides whether you keep it. The enforcement steps include the brownout: a short, announced window in which the old version deliberately returns errors, so that callers who ignore email find out while the harm is small.
Why a threshold is needed: an assumed adoption model
Assumptions, stated as assumptions: v1 traffic by client type is Python 40 percent, Java 25 percent, JavaScript 20 percent, Go 10 percent, raw HTTP 5 percent (sum 100 percent). If each month a fixed fraction r of the remaining v1 traffic moves to v2, the remaining share after n months is (1 - r)^n. The month in which it falls to a 5 percent target is n = ln(0.05) / ln(1 - r). Here r is simply the share of what is still left that moves in one month (r = 0.10 means a tenth of the remaining v1 traffic moves each month), and ln is the natural logarithm, the button on any calculator or math.log in code. The formula comes from solving (1 - r)^n = 0.05: take the logarithm of both sides to get n x ln(1 - r) = ln(0.05), then divide by ln(1 - r). For r = 0.10 that is -2.996 / -0.1054 = 28.4, and for r = 0.25 it is -2.996 / -0.2877 = 10.4.
| Monthly migration rate r | Remaining after 6 months | After 12 | After 24 | Months to reach 5 percent |
|---|---|---|---|---|
| 10 percent (passive) | 53.1 percent | 28.2 percent | 8.0 percent | 28.4 |
| 25 percent (with outreach) | 17.8 percent | 3.2 percent | 0.1 percent | 10.4 |
(Rates are assumptions, not measurements; the program in the next section prints the same figures.) The point is the shape: the passive curve has a long tail, still about 8 percent (7.98 before rounding) at 24 months, so waiting for customers to finish on their own does not produce a sunset date. Outreach to the biggest consumers and SDK-side adapters are what lift the rate.
The client mix shows which levers reach which traffic. The 95 percent of v1 traffic that comes from the four SDK languages can move with a one-line dependency bump, because the adapter in the old SDK minor does the work. The 5 percent that is raw HTTP has no SDK to carry an adapter or a warning, so it moves only when that team rewrites its calls after outreach or a brownout. The single-rate curve above does not model this split; in practice the raw HTTP share is the part most likely to form the slow tail, which is why the plan gives it its own outreach and brownout steps.
The formula and the SDK adapter, run
The first loop prints the table above. The class below is the old SDK minor from step 3: the caller still writes the same call and still receives a total in cents, while the request inside goes to v2 and the amount comes back as a decimal string.
import math
from decimal import Decimal
# Monthly migration model: a fraction r of the remaining v1 traffic moves each month.
for r in (0.10, 0.25):
left = [round(100 * (1 - r) ** n, 1) for n in (6, 12, 24)]
months = math.log(0.05) / math.log(1 - r)
print(f"r={r:.2f} remaining % after 6/12/24 months: {left}; months to 5%: {months:.1f}")
# Old SDK minor release: same method and result shape as before, but it calls v2 inside.
def fake_v2_get(order_id): # stands in for GET /v2/orders/{id}
return {"id": order_id, "amount": {"value": "19.99", "currency": "USD"}}
class OldSdkOrders:
def get(self, order_id):
body = fake_v2_get(order_id)
return {"id": body["id"], "total": int(Decimal(body["amount"]["value"]) * 100)}
print(OldSdkOrders().get(1042))
Output:
r=0.10 remaining % after 6/12/24 months: [53.1, 28.2, 8.0]; months to 5%: 28.4
r=0.25 remaining % after 6/12/24 months: [17.8, 3.2, 0.1]; months to 5%: 10.4
{'id': 1042, 'total': 1999}
Read-out: the two lines are the rows of the table (53.1, 28.2 and 8.0 percent remaining for r = 0.10, and 28.4 months to reach 5 percent; 17.8, 3.2 and 0.1 percent and 10.4 months for r = 0.25). The last line is what a customer on the old SDK sees: {'id': 1042, 'total': 1999}, the v1-shaped result, built from the v2 body 19.99. That is the customer-visible before and after: the call site does not change, only the dependency version does.
Milestones and enforcement
Assume the notice period is 12 months from announcement. Month numbers count from the announcement.
| Month | Milestone | Gate |
|---|---|---|
| 0 | New SDK majors and v2 generally available; announcement | Telemetry in place for 100 percent of SDK versions |
| 1 | New API keys default to v2 | No change for existing keys |
| 3 | Direct outreach to every consumer in the top 20 by v1 traffic; migration checker published | Each has a named contact and a plan |
| 6 | Warnings in old SDKs become more prominent; brownout 1 (1 hour) | Checkpoint: if more than 30 percent of the month-0 v1 traffic remains (the outreach curve above predicts 17.8 percent, the passive curve 53.1 percent), add engineers to outreach |
| 9 | Brownout 2 (4 hours) | Review the remaining list consumer by consumer |
| 12 | Sunset: v1 returns 410 Gone | Proceed if v1 is under 5 percent of requests and no top-20 consumer remains; otherwise one named extension of up to 3 months for those consumers only |
Enforcement should be graduated: warn, then brown out, then deny. Brownouts matter most when you cannot know upgrade dates, because they turn "someone eventually upgrades" into "this team finds out on a day you chose, with notice".
Judgment
I would commit to the dual running plus SDK adapters for the first year, and refuse to promise an unconditional sunset date before telemetry shows the first three months of migration rate. If the measured monthly rate after three months is close to the passive row of the table (around 10 percent), I would add dedicated migration engineering rather than extend the date; if the tail is a handful of known accounts, extend only for them.
Common mistakes
- Announcing without per-SDK telemetry, so the plan runs on opinions.
- Releasing a new SDK major but leaving old SDK versions silent about the deprecation.
- Treating the sunset date as fixed regardless of usage, or as endlessly movable.
- Forgetting raw HTTP clients, which have no SDK to carry warnings.
Running the code
Paste the program into a file and run it with Python 3.12; it needs no extra packages and prints exactly the output shown.
Thousands of clients across industries still call a version you want to retire. How do you identify who is actually calling it, including silent and long-tail consumers, set enforcement thresholds, and decide what to do when migration is slow or causes regressions?
Sample Answer
The idea in plain words
You cannot retire a version safely until you know who calls it, and the callers you most need to find are the ones who rarely appear: a job that runs once a quarter, a device in the field, a partner platform that calls on behalf of hundreds of its own customers. So the work is identification first (what the logs show, what they hide and how to surface the hidden ones), then enforcement in stages with go/no-go gates written as numbers, then a decision rule for the case where migration is slow or v2 turns out to cause regressions. A regression is a behaviour that got worse after the change, such as a higher error rate.
1. Identify the callers
Build a daily rollup from the access logs: one row per day, per caller identity, per version and route, with request count, error count and the set of User-Agent and SDK-version values seen. Caller identity means the strongest identifier you have, in this order: the key or OAuth client id (the identifier an application receives when it registers with an OAuth provider), then a service identity from mutual TLS (both sides present certificates, so the server learns the caller's service name from its certificate) or a tracing attribute (a caller name stamped on each request's trace data) for internal callers, then IP address range and User-Agent for the unauthenticated rest. The key is the identifier that matters most for external traffic; the later ones are fallbacks for callers that have no key.
Illustrative rollup rows:
day caller version route requests errors user_agents
2027-03-02 key_8f21 v1 GET /invoices 41 0 acme-sdk/2.3
2027-03-02 key_8f21 v1 POST /refunds 3 1 acme-sdk/2.3
2027-03-02 svc_batch v1 GET /invoices 12000 12 python-requests/2.31
Size check (upper bound, assumption-based): 5,000 keys x 20 routes x 400 days = 100,000 x 400 = 40,000,000 rows. That is small enough to keep in cheap analytical storage (inexpensive bulk storage queried in batches, such as files in object storage) for 400 days, which covers an annual job plus margin. The look-back matters more than the tooling.
The window changes the answer. Illustrative baseline: 2,500 keys called the old version in the last 180 days.
| Look-back | Keys seen | Keys missed vs the 180-day baseline |
|---|---|---|
| Last 7 days | 1,650 | 2,500 - 1,650 = 850 |
| Last 30 days | 2,050 | 2,500 - 2,050 = 450 |
| Last 180 days | 2,500 | 0 |
The 850 missed by a 7-day view split into 400 that called between 8 and 30 days ago (2,050 - 1,650) and 450 whose last call was 31 to 180 days ago. A weekly report would tell you migration was nearly done while hundreds of keys were simply between runs.
2. Find silent and long-tail consumers
- Periodic callers (monthly, quarterly, yearly jobs): found only by the long look-back; contact them before their next scheduled run, not after.
- Aggregators: one key that serves many downstream customers. Ask the partner for the downstream list, and require callers who act for others to send an identifier header you define, so you can count real consumers.
- Embedded or offline clients (devices, mobile apps): their update lag is the migration schedule; see telemetry by app version.
- Anonymous or shared keys: treat each shared key as one unknown consumer and route it to an owner by the account it belongs to.
- Surfacing by controlled failure: planned brownouts (short windows when the old version returns errors) make silent dependencies announce themselves. A graduated variant fails a small, rising fraction of idempotent read requests (for example 1%, then 5%) with
410 Gone(the status meaning permanently removed) and a message. Idempotent means that repeating a request has the same effect as sending it once, as with a GET that only reads; a failed read costs the caller one retry. Do not do this to writes: a failed write may leave work half done, or be duplicated when the client retries, so writes get announced windows only.
3. Internal consumers across many repositories
- Static detection: a scheduled job searches every repository for the old host, path prefix and generated client package (a client library produced from the API's specification), and lists dependency manifests (files such as
package.jsonorrequirements.txtthat list the libraries a project uses) that pin the old client. For example, a search finds the stringhttps://api.internal.test/v1/invoicesin a repository calledbilling-batch(illustrative). - Runtime detection: internal calls carry a service identity, so the gateway logs name the caller even where the code search finds nothing.
- Ownership routing: a service catalog (an inventory of services and the teams that own them) or CODEOWNERS files (files in a repository that list which team owns which paths) map each hit to a team, and the job opens one tracked ticket per team, or an automated pull request that swaps the client version. In the example, the catalog names the payments-ops team as owner of
billing-batch, so the ticket "Replace v1 invoices client in billing-batch" goes to them. - Prevention: a CI (continuous integration) lint rule fails any new change that adds a call to a deprecated route. As an illustration, it matches literal path strings in the languages it scans. It misses paths assembled at run time, URLs read from configuration and repositories nobody registered, which is why runtime detection stays on.
4. Enforcement thresholds and the go/no-go
Illustrative gates before starting brownouts, each a number that can fail:
- Gate A (coverage): keys still calling the old version are at most 10% of the 2,500-key baseline.
- Gate B (contracts): every remaining contracted account has a signed migration plan or extension.
- Gate C (health): the error rate of already-migrated keys on the new version is at most 1.5 times the old version's baseline.
Snapshot 60 days before the planned sunset (illustrative numbers): 220 keys remain; 9 of them are contracted accounts, 7 with signed plans; migrated keys show a 0.35% error rate against an old-version baseline of 0.20%.
- Gate A: 220 / 2,500 = 8.8%, pass (at most 10%).
- Gate B: 7 of 9 contracted accounts have plans, fail.
- Gate C: 0.35 / 0.20 = 1.75 times the baseline, fail (limit 1.5).
Decision: no-go for brownouts today. Contact the two contracted accounts without plans, investigate the regression, and re-evaluate in two weeks. The gates cover coverage, contracts and one health metric; a real process also reviews specific endpoints, latency and open customer escalations, and a human signs the decision.
5. When migration is slow or causes regressions
- Slow, with no regression: first stop growth (block new keys from the old version), then assist (migration engineer, codemod, office hours), then extend per key for a fee or milestones, and only then move the date.
- Regression on the new version: pause enforcement for the affected cohort, fix and verify, then reset the clock for that cohort only. Moving everyone's date for one bug punishes the customers who finished.
- Unknown and unreachable consumers: a final brownout schedule, then sunset, with the flag-based switch off kept for a quiet period so a surprise caller can be re-enabled while you contact them.
Pitfalls
- Treating "no traffic in the last week" as "no dependency".
- Counting requests only: a few hundred keys can hide behind low volume.
- Brownouts with no notice to the keys you already know about.
Unlock Full Question Bank
Get access to all 15 API Versioning, Deprecation and Backward Compatibility interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.