iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Bitmaps

A bitmap is a string treated as a packed array of bits. SETBIT / GETBIT flip and read individual bits. Use them for daily-active-user tracking, feature flags per user, presence, and approximate counts — constant memory regardless of bit count.

Daily-active users + bit ops

EXAMPLE
# Mark user 12345 as active today
SETBIT visited:2026-06-07 12345 1
SETBIT visited:2026-06-07 12346 1

# Did user 12345 visit?
GETBIT visited:2026-06-07 12345     # 1

# How many DAUs today?
BITCOUNT visited:2026-06-07          # number of set bits

# How many WAU? OR all 7 daily bitmaps together
BITOP OR weekly visited:2026-06-01 visited:2026-06-02 visited:2026-06-03 \
                    visited:2026-06-04 visited:2026-06-05 visited:2026-06-06 \
                    visited:2026-06-07
BITCOUNT weekly

# Users active EVERY day this week (intersection)
BITOP AND every visited:2026-06-01 visited:2026-06-02 visited:2026-06-03 \
                visited:2026-06-04 visited:2026-06-05 visited:2026-06-06 \
                visited:2026-06-07
BITCOUNT every

# Users active TODAY but not YESTERDAY (returning + new)
BITOP NOT  yesterday_inv visited:2026-06-06
BITOP AND  today_only    visited:2026-06-07 yesterday_inv

# Feature flag — per-user boolean across millions of users
SETBIT flag:new-onboarding "$USER_ID" 1
GETBIT flag:new-onboarding "$USER_ID"

# Memory cost: ~ floor(maxBit / 8) bytes.
# 100M users in one bitmap ≈ 12 MB.

Why it matters

Bitmaps + BITCOUNT + BITOP let you answer “how many users did X across a date range?” without a database. The whole pattern fits in tens of MB even at 100M users.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
SETBIT visited:2026-06-07 12345 1
GETBIT visited:2026-06-07 12345     # 1
BITCOUNT visited:2026-06-07
Try it Yourself »

Discussion

Loading…