Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Shopify Engineering 7 min read Case study mediumAdept

Leveraging Go Worker Pools to Scale Server-side Data Sharing

Shopify's Server Pixels service, a Go pipeline that consumes over a billion customer events per day from Kafka, fell behind on consumer lag because it spawned an unbounded number of goroutines to process and produce event batches. Replacing that with a fixed-size worker pool fed by a jobs channel, built on a reusable Worker interface and shut down gracefully with context cancellation and WaitGroups, bounded resource use. Throughput per pod rose from 7.75k to 12.9k events/sec with 15 workers, 19.3k with 50, and 21k after further tuning, a 170% gain. That headroom carried the service through a 46k events/sec peak during BFCM 2021.

Related posts

  • Keep the monolith, but split the workloads

    incident.io mediumAdept

    A Go monolith can get much of the reliability isolation of microservices by splitting workloads into separate deployments of the same binary, instead of breaking it into services. After a bad Pub/Sub message caused an unhandled panic that crashed the web, worker and cron threads together for 32 minutes, incident.io split them into independent Heroku dyno tiers selected by command-line flags. They also gave each class of work its own capped Postgres connection pool and statement timeout, so low-priority jobs such as BigQuery event export or best-effort nudges fall behind rather than exhausting the shared database. The main migration hazard is code that assumes a shared process, such as process-local caches, and the fix is to move that coordination into Postgres or Redis.

  • Worker Backpressure (Part 1)

    Canva Engineering mediumAdept

    Canva added Worker Backpressure to its shared queue library: each worker records success/failure outcomes, a pluggable controller maintains a backoff factor (0.0 to 1.0) against a failure-rate set point, and the factor scales down how many messages the worker may poll and process concurrently. Everything runs locally with no coordinator, at a cost of two arithmetic operations per cycle. In a 4-hour multi-spike cloud outage the DLQ grew by one message. In a 32.5-hour quota overload, 1.8M failed attempts produced only 22 DLQ messages, against an estimated 16,000+ without backpressure. The tradeoffs are reduced throughput for saturated workers and reliance on a single success/failure signal, with latency and in-flight signals planned as future additions.

  • How to Reliably Scale Your Data Platform for High Volumes

    Shopify Engineering mediumAdept

    Shopify's Data Platform Engineering team prepared Tier 1 and Tier 2 ingestion and query services for a forecast near-doubling of BFCM 2020 traffic with a five-step reliability process. The steps were to define each service's primary objective (a freshness SLO for the Longboat batch ingester, a latency SLO for Reportify), identify tunable knobs such as job frequency, overlap interval, GKE CPU/memory, BigTable node pools and ProxySQL pools, and constrain those knobs to simulate N-times load. Teams then validated that every alert was actionable with simple runbooks and decided where to scale or tune. The exercise led to cluster scale-ups and job and query tuning, and BFCM ran with a 150% throughput increase and only minor self-healing incidents.

  • Go Concurrency Patterns: Pipelines and cancellation - The Go Programming Language

    The Go Blog mediumAdept

    Go pipelines are built as stages of goroutines connected by channels, with fan-out to spread work across workers and fan-in (via a sync.WaitGroup-based merge) to combine results. When downstream stages stop reading early, upstream senders block forever and leak goroutines. Sizing buffers to avoid this is fragile. The robust fix is a shared done channel that is closed (via defer) to broadcast cancellation, with every send wrapped in a select. The patterns are applied to a parallel MD5 digest of a directory tree.

  • Using Server Sent Events to Simplify Real-time Streaming at Scale

    Shopify Engineering mediumAdept

    Shopify replaced its 2021 BFCM Live Map delivery path, in which WebSocket fed a presentation layer that clients polled through a mailbox system every 10+ seconds, with a Go Server Sent Events server. The server subscribes to Kafka topics produced by a Flink pipeline and pushes data straight to registered clients. SSE fit because the visualization only needs one-way, read-only push over plain HTTP with built-in reconnection; the server scales horizontally behind NGINX load balancers, and per-pod connection limits were sized with a Java load tester built on okhttp-eventsource. During BFCM 2022 the system had 100% uptime, SSE delivered data within milliseconds of availability, and end-to-end latency from event creation to display was about 21 seconds.

The quest for software engineering knowledge.

Look:
Layout: