skip to content

Core Data Structures

You will learn every native Redis type — strings, hashes, lists, sets, sorted sets, bitmaps, HyperLogLog, geospatial — plus the internal encodings that make them cheap. Interviewers probe this to see whether you pick the right structure and can predict its time and memory cost instead of treating Redis as a plain key-value store.

part ofRedisoverview, primer and where to startread it →
on this pageshow

explore

questions

page 2 of 2

Redis documents a standard error of about 0.81% and a footprint of about 12 KB for a HyperLogLog. What do those two numbers actually mean for a counter tracking roughly 50 million uniques, and why is a freshly created key far smaller than 12 KB?

level: seniorimportance: should knowfreq 32%

basics

~20 s

0.81% is a standard deviation, not a bound: at 50 million uniques a typical estimate is off by ~400k, and a couple of percent happens. 12 KB is the dense form of 16384 six-bit registers; small keys use a compact sparse encoding and convert to dense once they exceed hll-sparse-max-bytes, irreversibly.

open as a page

A worker pops a job from a Redis list with LPOP and crashes while processing it. Describe how the LMOVE and BLMOVE commands let you build a queue that survives this, and what that design still leaves you to handle yourself.

level: seniorimportance: should knowfreq 44%

basics

~20 s

With LPOP the job is gone the moment it is delivered, so a crash loses it. Instead use BLMOVE queue processing:<worker> LEFT RIGHT: it atomically pops and appends to a per-worker processing list, so the job stays visible. Remove it with LREM after success. You must still write the reaper for orphaned entries and make handlers idempotent.

open as a page

Product wants unique-user counts sliced by page, country and hour, and also wants to answer 'has user X visited this page?' and 'how many users saw both page A and page B?'. How do you decide which of these Redis HyperLogLog can serve, and what do you use for the rest?

level: principalimportance: should knowfreq 24%

basics

~20 s

HyperLogLog serves only the sliced counts, via one key per slice plus PFMERGE rollups. Membership and intersection are impossible with it: no per-element test, no PFINTERSECT, and inclusion-exclusion is numerically useless. Serve those with Sets, bitmaps over dense user IDs, or an offline store, and budget ~12 KB per dense slice key.

open as a page

You are designing catalog filtering by multiple tags on top of Redis Sets — users pick several tags and see the matching items. How would you model it, and what breaks as the catalog and tag cardinalities grow?

level: principalimportance: should knowfreq 38%

basics

~20 s

Model one Set per tag holding item ids, plus a reverse Set per item for maintenance. AND is SINTER, OR is SUNION, exclusion SDIFF. It degrades when every selected tag is huge: the work happens in one blocking command. Mitigate with selective-tag ordering, SINTERCARD LIMIT, SINTERSTORE into short-TTL result keys, and precomputed hot combinations.

open as a page

A leaderboard in Redis holds tens of millions of players and product now wants every player's exact global position plus deep pagination through the standings. Which parts of that stay cheap, which do not, and how would you architect around the limits?

level: principalimportance: should knowfreq 34%

basics

~20 s

Exact rank and top-N stay cheap — both are O(log N). Deep pagination by index is not: cost grows with the offset. Memory and single-key hotness are the real ceilings. Paginate by score cursor, serve reads from replicas, shard into cohort boards, and approximate global rank with score-bucket counters.

open as a page

Redis 6.2 introduced the GEOSEARCH and GEOSEARCHSTORE commands and deprecated the older GEORADIUS family. What do the newer commands add, and why could the original GEORADIUS not be executed on a read-only replica?

level: middleimportance: nice to knowfreq 22%

basics

~20 s

GEOSEARCH unifies GEORADIUS and GEORADIUSBYMEMBER (FROMLONLAT or FROMMEMBER) and adds rectangle search with BYBOX. GEORADIUS had an optional STORE clause, so Redis classified it as a write command and replicas refused it — hence the separate GEORADIUS_RO. GEOSEARCH is read-only; GEOSEARCHSTORE is the writing variant.

open as a page

What accuracy and coverage limits apply to Redis geospatial indexes — how exact are the coordinates returned by GEOPOS and the distances returned by GEODIST, and which coordinates cannot be stored at all?

level: seniorimportance: nice to knowfreq 18%

basics

~20 s

Coordinates are quantised to 26 bits per axis, so GEOPOS comes back within roughly a metre of what you wrote, never bit-identical. GEODIST is a great-circle distance on a sphere — a straight line, no roads, no altitude, with sub-percent error. Latitude is limited to about ±85.05°, so the poles cannot be stored.

open as a page

Redis supports lexicographic range queries on Sorted Sets (ZRANGEBYLEX, or ZRANGE with the BYLEX option). What must be true of the data for them to be meaningful, what is the interval syntax, and what are they used for?

level: seniorimportance: nice to knowfreq 32%

basics

~20 s

They only make sense when every member has the same score — then ordering is purely by member bytes and the sorted set becomes an ordered string index. Intervals need a prefix: [ inclusive, ( exclusive, - minimum, + maximum. Used for prefix search, autocomplete and cursor pagination.

open as a page

Redis's BITFIELD command lets you treat a string as an array of arbitrary-width integers with u8, i5 or similar types. When is that worth using instead of ordinary keys, and what do the OVERFLOW WRAP, SAT and FAIL modes control?

level: seniorimportance: nice to knowfreq 20%

basics

~20 s

BITFIELD packs many small integers into one string, addressed by bit offset and width (u1..u63, i1..i64). It runs GET/SET/INCRBY operations atomically in one command. OVERFLOW chooses what happens on wrap: WRAP wraps around, SAT clamps at the limit, FAIL returns nil and skips the write.

open as a page

You keep one Redis bitmap per day with a bit set for every active user. How would you use BITOP and BITPOS to answer questions like 'how many users were active on all seven days of last week', and what does that computation cost on the server?

level: seniorimportance: nice to knowfreq 28%

basics

~20 s

BITOP AND/OR/XOR/NOT combines bitmaps into a destination key, then BITCOUNT gives the answer: AND of seven day keys counts users active every day. It is O(total bytes) and writes a full-size result key, so batch it off the hot path, give the result a TTL, and mind memory.

open as a page

Your team proposes raising hash-max-listpack-entries and zset-max-listpack-entries from the default 128 to 4096 across the whole Redis fleet to cut memory cost. How would you evaluate that proposal, and what would you set instead?

level: principalimportance: nice to knowfreq 24%

basics

~20 s

It trades RAM for CPU on the single command thread: listpack access is a linear scan and writes may rewrite the whole blob, so 4096-entry values raise tail latency for every access. Evaluate per workload with measured memory and p99, set per-instance rather than fleet-wide, and prefer a moderate bump plus a hard cap on element size.

open as a page

You are designing a 'vehicles near me' lookup on Redis Cluster for a fleet of two million vehicles that report their position every few seconds. How would you lay out the geospatial keys, and what specifically breaks if you keep every vehicle in a single key?

level: principalimportance: nice to knowfreq 20%

basics

~20 s

One key lives in one hash slot on one shard, so a single global index pins every position write and every query to one core, and dense-area queries scan huge candidate sets. Partition by region (geo:{city}) or geohash-prefix cell, fan out to neighbouring cells client-side, and sweep stale members with ZREM since geo members have no TTL.

open as a page

showing 31–42 of 42