Skip to content
Dashboard

How we made global routing faster with Bloom filters

Link to headingThe path lookup operation

How the routing service checks if a requested path exists before serving it.How the routing service checks if a requested path exists before serving it.
How the routing service checks if a requested path exists before serving it.

Link to headingEnter Bloom filters!

How a Bloom filter inserts and queries keys using multiple hash functions.How a Bloom filter inserts and queries keys using multiple hash functions.
How a Bloom filter inserts and queries keys using multiple hash functions.

Link to headingHow the new path lookup optimization works

Link to headingThe deploy process

{"version":"test","bloom":{"n":10,"p":1e-7,"m":336,"k":23,"s":0}}
"0kxC4anU4awVOYSs54vsAL7gBNGK/PrLjKrAJRil64mMxmiig1S+jqyC"

Link to headingServing routes

-- Fast lookup table for translating Base64 characters to their values
-- This is used to decode the Base64 encoded bit array in the Bloom filter
local b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
local decode_table = ffi.new 'uint8_t[256]'
for i = 1, #b64 do
decode_table[str_byte(b64, i)] = i - 1 -- Base64 values start from 0
end
function BloomFilter:has(key)
local ptr = self.ptr -- uint8_t* pointer to start of Base64 string
for byte_offset, bit_offset in self:iterator(key) do
local sextet = decode_table[ptr[byte_offset]]
if band(sextet, lshift(1, bit_offset)) == 0 then
return false
end
end
return true
end

Link to headingNear-zero latency and 10% faster routing

Heap and memory usage reductions after Bloom filter rollout.
Heap and memory usage reductions after Bloom filter rollout.
P50 to P99.9 latencies improved following the switch to Bloom filters.
P50 to P99.9 latencies improved following the switch to Bloom filters.
P75 and P99 TTFB improved after Bloom filter rollout.
P75 and P99 TTFB improved after Bloom filter rollout.