At Stripe, I was the DRI for moving a new core service into the hot path. The service provided IAM and account data to all of Stripe's API traffic. It was new, so we had spun it up on shadow traffic: the Ruby monolith kept serving the real answers, and our service took a copy of every request so we could monitor it over time.

The monolith's Ruby models were gigantic. We had denormalized them into smaller, more performant models accessible from Java (why Ruby vs Java was split is a later story). After enough time in shadow, it was time to flip it into the actual hot path, fail closed, and be on the hook.

Exit criteria

Two numbers: 99.9995% availability and p99 latency under 10ms.

99.9995% is about 2.6 minutes of downtime a year.

For reference, when we started we were at 99% and 25ms.

99% is 3.65 days of downtime a year.

Planning it

The project spanned five teams: account services, IAM, Platform, Mongo, and Deploy. I led the planning, scoping, exit criteria, and the project work. The approach:

  1. What were we trying to accomplish as a business?
  2. What did we need to do technologically to support that?
  3. What technical changes get us there?
  4. Separate it into milestones. What's most important, what's least, what work belongs together?
  5. Estimate, set expectations, execute. Come up with the dev work needed to fulfill all the requirements, surface it to the highest levels of reach respective org/team required, set expectations for when it can be done with X engineers, and execute the plan.

We had a lot of dependencies: more database availability, platform support and features, deployment strategies. Getting other teams to buy in came down to two things: talk about business goals and needs, and be explicit in requirements.

The work

There were a ton of items we took on to get there. Thread pools and the database moved the numbers the most, so those first.

Thread pools. Exhaustion was the natural progression of Little's law on our hosts. concurrency = throughput x latency, so as traffic grew and any downstream call slowed, in-flight requests climbed until the pool was full and everything queued behind it. We bulkheaded the thread pools across data access patterns, so a slow pattern could only saturate its own pool instead of backing up everything else. We propagated request deadlines downstream, so a request that was already going to time out stopped holding a thread, and tuned pool sizes and max request deadlines against our egress traffic. Bigger hosts on top of that gave us more goodput, and right-sizing them saved money at our scale.

Database. We had unexpected failovers, queries that could be optimized, and shared load from other services on the same database. We moved towards further isolation, migrated our database hardware to a higher version/bigger instances, and moved reads to secondaries safely and incrementally when possible. A lot of analysis of DB internals and schemas came into play here.

Reads from secondaries can lag the primary, and for IAM and account data that means answering with permissions or account state that just changed. We didn't want to guess which reads could tolerate that, so I built a mechanism I called STOV (synthetic traffic, online validation). It would sample live customer requests immediately after they fired, replay each one against the legacy service and against ours, and diff the responses. It ran continuously, and each step of moving reads over was gated on the diffs staying clean.

Some of the rest:

Warmup and caching. A freshly deployed host serving cold is a tail latency hit: the JIT hasn't compiled the hot paths yet, connection pools are empty, caches are empty. We improved our warmup hooks so a host was actually warm before it took traffic, preseeded caches, and tuned caching behavior off of the read patterns we were actually seeing instead of what we assumed they'd be.

Infrastructure. Natural progressions of services, such as autoscaling to follow traffic, overscaling on top of that so a spike or a lost host didn't push us back toward pool exhaustion (waiting for autoscaling can be a pain), and making sure hosts were spread across AZs so a single-zone problem couldn't take out a meaningful share of our capacity.

Upstream systems. Our availability was capped by whatever we depended on, so those had to be productionized too. We tuned GC on the Ruby processes upstream of us, ran what felt like infinite load tests again upstreams, and fixed what turned up.

Ops. Gamedays, better runbooks and documentation, and the issues we discovered along the way as a result.

SLCs

We defined calculated SLAs for our service and turned them into SLCs (service level commitments) with our clients. This was a good point of disagreement and commitment. Buy-in came from the benefits: SLCs drive up reliability and confidence, clients understand what to expect, and problems get surfaced correctly.

SLCs were a big point of contention -- many folks wanted to just commit to their observed availability. "Our service over the past month runs at 99.99% availability, so that is our SLC." The problem in doing so becomes projecting availability for the future. If your upstreams are all committed to 99% uptime, it's impossible for you yourself to be committed to anything greater. In fact, you often have to commit to the product of your upstreams SLCs! Pushing dependencies to up their SLCs allowed us to feel confident that they had the measures in place to conform to higher values, which provided us the confidence to conform to ours.

The flip

A percentage ramp, with a lot of monitoring for the services that depended on us. We added org-wide and multi-team synthetic tests into deploy health and alarms, and watched each them at every leg of the rollout.

We had to roll back a few times to fix latent bugs. Perks of having a good rollback strategy and alarms. We got there over time, but the initiative took about ~3 quarters from start to finish. It's critical to have easy rollback-ability, and you need high value signal to determine when that is necessary. In famous ops-fashion: "rollback first, ask questions later".

Our Java service was the pilot Java microservice at Stripe, and this was the first productionization effort we accomplished there. This project ended up serving as the example for future services making the same move.