Skip to content

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

Shopify Engineering 10 min read Case study mediumAdept

Dynamic ProxySQL Query Rules

Shopify runs thousands of ProxySQL instances in front of MySQL and uses query rules to reroute, rewrite or reject queries matching a regex, often during incidents. To make rules safe, they patched their ProxySQL fork with a dry-run mode (active=0, log=1) that logs matched queries with exponential backoff instead of acting on them. A web app writes rules to a global key-value store, and a sidecar next to each ProxySQL polls it and syncs the mysql_query_rules table. If the sidecar and ProxySQL drift, both rule lists are wiped and rebuilt, favouring consistency over availability; rules also carry TTLs, and rules that must always be present are loaded statically from proxysql.cnf.

Related posts

  • Beyond synthetic testing: Capturing and replaying real database workloads at Airbnb

    Airbnb Engineering mediumAdept

    Airbnb replaced fragmented per-language client-side query logging with a client-agnostic capture point in ProxySQL, so real production MySQL traffic can be replayed offline. A Log Mover sidecar ships ProxySQL query logs to object storage. A Log Processor splits them per cluster, reassembles transactions, buckets them into five-minute windows and rewrites INSERTs to pin last_insert_id. A queue-driven fleet of replay workers then uses shared start times to reproduce the original concurrency and pacing, at 1x or accelerated speeds. Replay-and-compare runs during the MySQL 5.7→8.0 upgrade caught a 0.03s→2.6s sort regression, duplicate queries the query cache had been hiding, and non-deterministic ORDER BY/LIMIT results. Accelerated replays locate capacity ceilings, for example commit latency rising from 6 ms to 34 ms at 80% more write traffic.

  • How Shopify Dynamically Routes Storefront Traffic

    Shopify Engineering mediumAdept

    Shopify shifted storefront traffic from its legacy Rails storefront to a rewritten renderer using a rule-based routing system in nginx/OpenResty Lua load balancers, with rules stored as JSON in a control plane and managed via the spy chatbot so changes skip CI and deploys. Each rule specifies filters, target shop IDs, and sampling rates for rendering, forward verification (legacy renders, new storefront checked), reverse verification, and self-verification against the local region's deployment. Rules are checked in the nginx rewrite phase, verification is decided in the header filter phase, and duplicate requests are sent asynchronously via nginx timers in the log phase so clients never wait on both upstreams. The same mechanism let the team mirror traffic to a separate deployment disconnected from Redis to test resilience before BFCM.

  • Shard Balancing: Moving Shops Confidently with Zero-Downtime at Terabyte-scale

    Shopify Engineering mediumAdept

    Shopify rebalances its MySQL shards by moving individual shops between pods online, with downtime confined to a brief cutover. Placement is decided by simulating proposed moves against historical utilization data, which in one case narrowed the spread between least- and most-used shards from about 4x to about 2x. The move itself uses Ghostferry, which batch-copies rows filtered by shop_id using SELECT...FOR UPDATE while tailing the row-based binlog to replay concurrent writes. Once replication lag is near real time, a Redis-backed multi-reader-single-writer lock halts writes for the shop so remaining binlog events can drain, after which the routing table is updated, the lock released, the move verified and stale data pruned from the source shard.

  • Optimizing Data Reliability: Heroku Connect & Drift Detection

    Heroku Engineering easyNovice

    Heroku Connect syncs Salesforce data into Postgres by polling time windows, and long-running Salesforce transactions that commit after the window has moved can be missed, causing drift. A secondary poll re-runs the same poll bounds later to catch those changes. For Bulk API polls it now creates one bulk job per primary job, with a batch per primary batch, instead of many jobs. It also caps how many secondary tasks run at once, which reduces load on the Salesforce org and leaves more Postgres connections free for customer applications.

  • Partitioning GitHub’s relational databases to handle scale

    GitHub Engineering mediumAdept

    GitHub split its monolithic `mysql1` MySQL cluster by first virtually partitioning tables into schema domains (declared in YAML) and enforcing boundaries with query and transaction linters, then physically moving domains to new clusters via Vitess vertical sharding or a custom ProxySQL/GTID-based write-cutover script. Cross-domain joins were eliminated with techniques like preload, Rails' new `disable_joins` option and application-side joins, validated with Scientist experiments. The write-cutover moved 130 of the busiest tables in tens of milliseconds with only a handful of failed writes. Query volume grew from 950k to 1.2M queries/s while average per-host load halved, reducing database-related incidents.

The quest for software engineering knowledge.

Look:
Layout: