FOQS: Scaling a distributed priority queue

This post introduces FOQS (Facebook Ordered Queueing Service), a new fully managed, horizontally scalable, multitenant, persistent distributed priority queue built on sharded MySQL. FOQS enables developers to decouple and scale microservices and distributed systems by providing a robust queueing mechanism with features for item prioritization, delayed delivery, and configurable delivery semantics (at-least-once/at-most-once). It details the item structure (namespace, topic, priority, payload, metadata, deliver_after, lease duration, unique ID, TTL), topic and namespace concepts, and the implementation details of Enqueue, Dequeue, Ack, and Nack operations. Key architectural components include Shard Manager for shard assignment, a Thrift API, circuit breaker design for shard health, and a Prefetch Buffer for efficient high-priority item retrieval during dequeues. The post also discusses the rationale for a pull-based interface over push for diverse workload needs.
More from the Scalability and Large-Scale Systems Engineering trail
- Open-Sourcing Rebalancer: A Generic, High-Performance Library for Solving Assignment Problems
- ZGateway: Learnings from Putting a Proxy in Front of ZippyDB
- MTIA 300: Meta’s First Training Chip with Built-in NICs and Communication-Offloading Engines
- From User Sequences to Scaling Laws: A Multi-Stage Architecture for Meta’s Ads Ranking
- GEM Training: How Meta Doubled the Efficiency of Its LLM-Scale Ads Foundation Model