When I was on API Gateway, there were hundreds of millions of APIs out there. Depending on how an API was configured, some of them got a CloudFront distribution all to themselves: one API, and one distribution sitting in front of it at the edge.
That's a perfectly reasonable design when the API is doing something. The problem was that most of them weren't.
The tire-kickers
Anyone who's worked on a developer product knows the pattern. Someone reads a tutorial, clicks "Create API", sends three requests, and never comes back. Multiply that by a few years of growth and you end up with roughly 10 million APIs that saw nothing more than trickle traffic, each one holding its own distribution.
Every one of those distributions cost us capacity, counted against our limits, and added to the operational load. Compute at that scale was genuinely hard to come by, and we were burning through it so fast that we had to request limit increases every one to three months (a common ticket for our on-calls).
One generic distribution per region
The fix was to stop giving the same amount of infrastructural resources to each API. Instead of a 1:1 ratio of distribution to API, I moved the idle ones behind a single generic, multi-tenant distribution in each region. There was no fixed ratio: it took an arbitrary number of APIs, as many as were idle, and constant monitoring and feedback kept it honest.
Each region's generic distribution answered on that region's wildcard domain, *.execute-api.{region}.amazonaws.com, and routed each request to the right API based on its hostname. The neat part is that the more specific name always wins, in DNS and in CloudFront. Any API that still had its own record and its own distribution kept using them, and the wildcard only picked up the APIs I had deliberately moved over. We only touched execute-api domains. Those live on DNS that AWS controls, so we could move them without asking a single customer to change anything. Custom domains didn't matter here either: from the customer's side, the execute-api URL stayed exactly the same, so there was nothing for them to notice.
Moving APIs without touching their traffic
The actual cutover was a DNS change and a lot of DB backilling: point an API's record at its region's generic distribution instead of its dedicated one. The rule was no breaking changes. Every request had to be served exactly the same way before, during, and after the move, and the crafty part was guaranteeing that. It helped that CloudFront already picks a distribution by hostname, so moving an API behind a shared one changed nothing a client could see.
- Pick carefully. An API only qualified based on its historical traffic: volume had to stay under our thresholds for months in a row. A single quiet week didn't count.
- Serve from both sides. The generic distribution was ready to serve an API before its record moved, and the old distribution stayed up until cached DNS answers had expired. A client holding a stale answer still landed somewhere that worked. Only then did we kill the old distribution and reclaim the capacity.
- Move in waves. Small batches first, then bigger ones, with migrations and backfills tracking which API lived where. AWS is an infrastructural place (of course), and using official CMs (Change Management) to facilitate this was the only path.
- When in doubt, don't move it. If a migration looked wrong, the API stayed on its old distribution while I investigated, and I retuned our thresholds before trying again.
Watching for the ones that wake up
Packing that many APIs together is fine right up until a subset of them become popular. As a result, each generic distribution came with capacity alarms and consistent monitoring. The rule was simple: if an API got hot, it got its own distribution again.
What it bought us
Once an API had moved, its old distribution was serving nothing. So I deleted them. All of them! Roughly 10 million distributions that had existed only to sit in front of APIs nobody was using were simply gone.
Our usage dropped by double digit percentiles. More importantly, I built the consolidation as an ongoing process rather than a one-time cleanup: it kept finding newly idle APIs and moving them behind the generic distributions.
It turned a limit increase every few months into headroom measured in ~years. I didn't file another limit increase for the rest of my time on the team.
The same idea carried straight into my next project, VPC Link V2. A VPC link keeps network interfaces (ENIs) in the customer's subnets, and those are far heavier to keep around than an idle API behind a shared distribution. So I built a reaper for them. If a VPC link sees no traffic for 60 days, it goes INACTIVE and its ENIs are deleted. When traffic comes back, they're reprovisioned within a few minutes. link
Unlike the distributions, that one was a deliberate tradeoff. While a link is INACTIVE, requests through it fail until the ENIs are back. Keeping heavy resources warm for links nobody had touched in two months wasn't worth it. It's still how VPC links behave today, and it probably deserves its own post.