Performance at GitHub: deferring stats with rack.after_reply
GitHub cut 30ms at p50 and 50ms+ at p99 from every request by buffering statsd metrics during a request and flushing them in one batch through `rack.after_reply`, a hook that runs callables after the full response reaches the client. Flamegraphs had shown statsd calls costing up to 65ms per request. Rack::Events was rejected because its callbacks blocked the response from closing. GitHub added `rack.after_reply` support to Unicorn upstream and wrapped it in a small AfterResponse class. The tradeoff is that the Unicorn worker stays busy until the callables finish, which can increase HTTP queueing, so GitHub added timeouts to bound the deferred work.
Related posts
- How we improved availability through iterative simplification
GitHub Engineering mediumAdeptGitHub cut timeouts in its Rails monolith with small, measured changes found through Datadog metrics, Splunk logs and custom MySQL slow-query monitors. Each change was validated with Scientist experiments or rolled out gradually behind Flipper feature flags. Reordering a Command Palette query to look up a user's contributions before filtering by org removed a large IN clause and was 80-90% faster, and batching access checks added another 20-80% and 30-40%. Skipping unneeded authorization filters on a busy redirect endpoint cut tail latency and timeouts. Not every idea paid off: moving sorting into the application was 40-80% slower, so that experiment was dropped.
- Incident Report: November 20th, 2025
Railway easyNoviceA dip in GitHub push webhooks followed by a 10x surge flooded Railway's asynchronous deployment task queue, delaying all new deployments for about two and a half hours on November 20th, 2025. Workers locked up under memory pressure, so the team added and restarted workers and shed load by disabling deployments tier by tier (Free/Trial/Hobby, then Pro), re-enabling them in reverse order as recovery came. Running services and networking were unaffected. Follow-ups include segmented queue alerts, monitoring for deployment spikes, and fixing the worker lockup under memory pressure.
- Node.js at scale, rebalanced: how we cut cost by 38%
Booking.com Engineering mediumAdeptBooking.com cut compute costs for its largest Node.js React SSR service by 38% (30% fewer pods, 20% less memory per pod, up to 10% lower tail latency) without touching service code, by moving from pm2's cluster-based processes to wattpm worker threads and revisiting long-untouched configuration. Synthetic k6 tests showed 20-50% more throughput within latency SLOs, validated through a side-by-side production A/B split at the routing layer. Production exposed uneven worker load because SO_REUSEPORT's connection hashing interacted badly with nginx loopback connections recycled via tcp_tw_reuse. Giving each worker its own port and load-balancing in nginx fixed it, which also opened the door to smarter balancing between heavy renders and light metadata requests.
- To Thread or Not to Thread: An In-Depth Look at Ruby’s Execution Models
Shopify Engineering mediumAdeptThreaded Ruby servers like Puma and Sidekiq save memory over forking servers, but the gap is smaller than RSS suggests once copy-on-write sharing is measured properly with PSS and /proc/$PID/smaps_rollup. In one Shopify production app an extra Unicorn worker cost about 427MiB versus about 257MiB for an extra thread, not the ~750MiB RSS implied, and preloading plus eager loading improves CoW efficiency. Processes still offer clean request timeouts and avoid Global VM Lock contention, which hurts latency more than commonly assumed because Ruby web requests are less I/O-heavy than believed and GC also holds the GVL. Ractors and Fibers are not drop-in replacements, and a proposed GVL instrumentation API for Ruby 3.2 would let teams measure the latency cost of threads.
- Incident Report: November 25th, 2025
Railway mediumAdeptSlow GitHub API calls (about 4x normal p95 latency) during peak hours backed up Railway's Temporal-based task queue, causing workers to run out of memory and crash in a cascading thundering-herd pattern as surviving and newly started workers were overwhelmed by the backlog. Deployments for Free, Trial and Hobby tiers were paused and Pro deploys delayed for roughly two and a half hours, while running services stayed online. Recovery came from increasing worker CPU and memory and fixing worker parameters that made them request more tasks than they could handle. Follow-up measures include an auto-tuning algorithm for worker task intake, more task queue capacity, and removing external API dependencies from critical workflows.