A filter that trades memory for a bit of CPU

Bloom filters are the standard tool for quickly determining whether a key is not in a set. By overapproximating the set of keys associated with a resource, they let storage systems skip nearly all negative lookups. But they pay for that speed: a conventional Bloom filter uses roughly 50 percent more space than the information-theoretic lower bound for filters over arbitrary keys. The Ribbon filter, a new data structure from researchers at Facebook, shrinks that overhead to as little as 1 percent or less while preserving the practical configurability that made Bloom filters so widely adopted.

Unlike some earlier Bloom alternatives, Ribbon filters avoid the classic configurational hazards. "Near-continuous" configurability means the filter can efficiently use any amount of memory for any number of keys, rather than being constrained by bit alignment that makes certain sizes (e.g., 4, 8, or 16 bits per key) faster than others. Ribbon filters sidestep those discontinuities and, for a given space budget, save roughly one-third of the memory that a Bloom filter would consume, at the cost of slightly more CPU time. Queries remain O(1). The trade-off covers any three of the four core dimensions — number of keys, memory, CPU, and accuracy — with accuracy automatically optimized for the remaining space.

Solving equations instead of setting bits

The construction is reminiscent of certain perfect hashing schemes. A Ribbon filter is built by solving a linear system over GF(2), where each row expresses that querying for a particular key — performed by XOR-ing the values at a set of array indices — must produce a prescribed output indicating the key is present. The system is solved by Gaussian elimination, the same technique taught in linear algebra: subtract equations from each other until variables are isolated.

What makes this tractable is the structure of the coefficient matrix. The linear system, based on work by Dietzfelbinger and Walzer, has a sorted coefficient matrix that resembles a physical ribbon — a wavy approximation of a band matrix. Because it is already close to a reduced form, Gaussian elimination is far more efficient than on arbitrary dense systems.

The name also doubles as an acronym: Rapid Incremental Boolean Banding ON the fly. Rather than building and reducing the full system in memory, the construction algorithm performs row reductions on the fly, similar to inserting into a linear-probed hash table. This keeps intermediate work in registers rather than main memory, and the reduced band-matrix form takes less space than explicitly representing the ribbon structure. The on-the-fly approach also solves a key scaling problem: making the filter space-efficient for very large key sets.

A practical drop-in alternative

Space savings are not the only engineering consideration. Past Bloom alternatives that promised memory reductions were slow to see adoption because they were awkward to integrate. The Ribbon filter is designed to be used with a relatively simple API, with the internal complexity hidden from the caller. For static (immutable) data sets, it offers a near-continuous accuracy-versus-space trade-off that is comparable to that of Bloom filters, minus the space overhead.

At Facebook's scale, the projected impact is significant: saving several percent of RAM across major storage systems with only a small CPU increase. For workloads where Bloom filters already meet space targets, they remain an excellent choice — and extremely fast. The Ribbon filter is aimed at the cases where they do not, providing finer-grained control to close the gap between resource usage and the information-theoretic limit.