Menu

1 / 2

From 32KB SQL Joins to 46 Bytes: Architecting an O(1) Habit Streak Engine with Valkey/Redis Bitmaps & POPCNT

DEV Community: redis·Duong Phuc Khanh (Kido)·about 18 hours ago
#HraPV2En
#devtoredis#devto#dev#date#bytes
Reading 0:00
15s threshold

Every morning at 06:00 AM, thousands of athletes open their fitness habit tracker simultaneously. Each user expects to instantly see their current streak, total workout count for the year, and an interactive GitHub-style 365-day habit heatmap.

In traditional relational database designs, calculating this single screen requires querying a table containing millions of daily event rows:

-- The Naive SQL Approach: Relational Habit Check-ins SELECT checkin_date FROM habit_logs WHERE user_id = 48291 AND habit_id = 101 AND checkin_date >= '2026-01-01' ORDER BY checkin_date ASC ;

Enter fullscreen mode

Exit fullscreen mode

When 10,000 active athletes hit this query within a 15-minute window, database connection pools choke, B-Tree index pages flood buffer memory, and p99 query latency spikes past 140ms .

I'm Dương Phúc Khánh (widely recognized in the engineering ecosystem as khanhdp or Kido , @khanhduong22 ).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.