FOQS: Making a distributed priority queue disaster-ready
Meta's FOQS distributed priority queue moved from isolated regional installations on semi-synchronous replicated MySQL to a single global installation, after Hurricane Florence in 2018 exposed manual traffic rebalancing and items stuck on unreachable shards. The global design uses Shard Manager so a queue node in the new region takes over a MySQL primary within seconds of failover. A routing service maps logical region preferences to shards for enqueue and keeps a heap-based cache of nodes with ready items for dequeue. Migrating the Async platform required parallelizing cache replenishment, which nearly halved its latency, and randomizing selection among top-priority nodes to fix thundering herd and starvation. The 2021 migration finished with zero downtime using shadow load testing, config-based rollouts and health dashboards.
Related posts
- Asynchronous computing at Meta: Overview and learnings
Meta Engineering mediumAdeptMeta re-architected Async tier, its serverless asynchronous computing platform running multi-trillion workloads per day, by splitting an overloaded Dispatcher into data-source-specific "tailers" and a source-agnostic scheduler. Tailers now push work to the scheduler over RPC instead of the scheduler pulling from the FOQS queue. This removed redundant copying into FOQS, improved end-to-end latency and cross-region load balancing, and made streams, warehouses and pub/sub first-class sources, at the cost of being a poor fit for long-running workloads. Queues offer lease-based granular retries and flexible ordering at moderate cost, while streams are cheaper for high-volume sequential access but clog on failed items. A separate controlled-delay service, backed by a priority queue or chained fixed-delay streams, preserves at-least-once delivery without blocking the stream.
- How Meta built the infrastructure for Threads
Meta Engineering mediumAdeptThreads reached 100 million sign-ups in five days on existing shared Meta infrastructure rather than purpose-built systems, illustrated through two components: ZippyDB and Async. ZippyDB, a multi-tenant key/value store, absorbs sudden demand by shifting unused allocations and slack between keyspaces via config changes. It scales out with a zero-downtime resharding protocol that remaps logical shards to new physical shards, which let the team proactively prepare Threads keyspaces for 100x growth just before launch. Async (XFaaS), a serverless deferred-execution platform, queued the far-higher-than-expected follow-graph imports and notification jobs and rate-limited their execution to protect downstream services such as the social graph database.
- Shard Balancing: Moving Shops Confidently with Zero-Downtime at Terabyte-scale
Shopify Engineering mediumAdeptShopify 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.
- Beyond synthetic testing: Capturing and replaying real database workloads at Airbnb
Airbnb Engineering mediumAdeptAirbnb 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.
- Keep the monolith, but split the workloads
incident.io mediumAdeptA 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.