GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - atonyhonesto/race-data-redis-streams: Python race-timing example using Redis Streams, consumer groups, acknowledgments and replay.

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
racestream
racestream
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
demo.py
demo.py
 
 

Repository files navigation

๐Ÿ race-data-redis-streams

Live timing for every car, delivered to every system that needs it, with nothing lost when a consumer dies.

ci Python Redis Dependencies

Companion code for my LinkedIn article
Race Data Streaming with Redis โ†’


Why Streams, not pub/sub

Redis pub/sub is fire-and-forget: a subscriber that blinks misses laps forever. A stream is an append-only log that keeps entries, so every consumer reads at its own pace, consumer groups share the work and track what's been acknowledged, and a dashboard that connects late can replay what it missed.

flowchart LR
    T["โฑ๏ธ Timing loop<br/>XADD race:timing"] --> S[("race:timing<br/>stream")]
    S --> G1["group: strategy"]
    G1 --> A["worker-a"]
    G1 --> B["worker-b ๐Ÿ’ฅ"]
    B -. "unacked โ†’ XAUTOCLAIM" .-> A
    S --> G2["group: leaderboard"] --> L["board-1 โ†’ ZADD LT race:best"]
    S --> D["late dashboard<br/>XREVRANGE, then XREAD BLOCK $"]
Loading

Run it

git clone https://github.com/atonyhonesto/race-data-redis-streams.git
cd race-data-redis-streams
python demo.py          # starts a throwaway redis-server if one is installed
# or point it at any Redis 6.2+:
docker run -d -p 6379:6379 redis:7
REDIS_URL=redis://127.0.0.1:6379 python demo.py
python -m unittest -v   # 7 tests against a real Redis

Real output:

Redis 7.0.15 at redis://127.0.0.1:55815

1. Timing loop publishes 40 laps with XADD (stream length 40)

2. Group 'strategy' splits the work: worker-a took 10 (acked), worker-b took 10 then crashed
   XPENDING: 10 delivered but unacknowledged -> {'worker-b': 10}

3. worker-a finishes the 20 remaining laps, then XAUTOCLAIMs worker-b's 10 stale ones
   XPENDING now: 0  -> every lap handled once the group settles (at-least-once)

4. Group 'leaderboard' independently reads all 40 laps from the same stream
   P1  car 24  best 40.365 s
   P2  car 77  best 40.486 s
   P3  car  5  best 40.503 s
   P4  car 48  best 40.978 s

5. A dashboard joins late: XREVRANGE for the last 4 laps, then it would XREAD BLOCK from '$'
   1791456890307-4  car 77  lap 10  40.486 s
   1791456890307-3  car 48  lap 10  41.427 s
   1791456890307-2  car 24  lap 10  40.982 s
   1791456890307-1  car  5  lap 10  40.857 s

6. XINFO GROUPS
   leaderboard  consumers 1  pending 0  last-delivered 1791456890307-4  lag 0
   strategy     consumers 2  pending 0  last-delivered 1791456890307-4  lag 0

Commands used, and why

Command Job here
XADD race:timing MAXLEN ~ 10000 * โ€ฆ Append a lap. MAXLEN ~ caps memory cheaply (approximate trimming)
XGROUP CREATE โ€ฆ MKSTREAM Durable consumer group; start at 0 (history) or $ (new only)
XREADGROUP GROUP g c COUNT n [BLOCK ms] STREAMS race:timing > Get entries never delivered to this group; BLOCK waits for new laps without polling
XACK Done with it. Unacked entries stay in the pending list
XPENDING Who's holding what: how you notice a dead worker
XAUTOCLAIM Take over entries idle longer than a threshold
XREVRANGE + - COUNT n Replay recent history for a late joiner
ZADD race:best LT Leaderboard that only ever improves a car's best lap
XINFO GROUPS Pending count, last delivered ID and lag per group

Design notes

  • At-least-once. A crash between processing and XACK means the lap is processed again after the claim. Make handlers idempotent (the ZADD LT leaderboard is naturally).
  • Groups are independent. Strategy and leaderboard both see every lap; adding a third consumer type doesn't touch the others.
  • IDs are time-ordered (<ms>-<seq>), so a range query by time needs no extra index.
  • The client is ~50 lines (resp.py) to show how simple RESP is. In an application use redis-py, StackExchange.Redis or ioredis: same commands, with pooling and reconnects.

Project layout

racestream/
  resp.py      minimal RESP2 client
  timing.py    producer, groups, read/ack, claim, leaderboard, replay
  server.py    REDIS_URL or a throwaway redis-server
demo.py        the scenario above
tests/         against a real Redis (a service container in CI)

Built by Tony Honesto, cloud & integration engineer with roots in IndyCar timing & scoring and NASCAR Race Control. More: github.com/atonyhonesto ยท article-labs ยท LinkedIn

About

Python race-timing example using Redis Streams, consumer groups, acknowledgments and replay.

Topics

consumer-groupsevent-streaminggithub-actionsmotorsportpythonredisredis-streamstelemetry

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.