Labs / Data
DataWorking~7h
Cache-Aside Read Path with Correct Invalidation
A read-through cache-aside layer in front of a PostgreSQL-backed API: reads check Redis first and populate on miss, writes invalidate (not update) the cache key inside the same transaction boundary as the DB write, and a race-condition test proves no stale value survives a concurrent read-during-write.
Что это доказывает
Строка, которую вы сможете защитить на собеседовании.
Строка для резюме
Built a cache-aside layer with write-path invalidation and TTL fallback, eliminating stale reads under concurrent read/write load, validated with a race-condition test suite against Redis and PostgreSQL.
- map
- decide
- prove
Краткое описание
Что вы создаёте, шаг за шагом.
- 01GET /resource/:id checks Redis by key first; on miss it reads PostgreSQL, writes the value to Redis with a TTL, and returns it
- 02PUT/PATCH /resource/:id writes to PostgreSQL first, then deletes (not updates) the corresponding Redis key so the next read repopulates from source of truth
- 03Cache key includes a version or entity-type prefix so invalidation can never accidentally hit an unrelated key
- 04A TTL is set on every cache write as a safety net independent of explicit invalidation, in case a delete is missed
- 05Write path uses a DB transaction that only triggers the cache delete after commit succeeds, so a failed write never invalidates a still-correct cached value
- 06A documented decision note explains why invalidate-then-lazy-repopulate was chosen over write-through update, including the race it avoids
Доказательство
Готово, когда эти проверки пройдены.
After an update, a read issued immediately after returns the new value, never the pre-update cached value
automated test
Concurrent test: read request in-flight during a write does not leave a stale value cached afterward (verified by a follow-up read)
automated test
A failed/rolled-back DB write does not delete or corrupt the existing valid cache entry
automated test
Cache hit vs miss is observable via response headers or logs, used to assert hit rate in tests
automated test
Стек
Node.jsRedisPostgreSQLVitestDocker Compose
Метод Sage
map → decide → prove
Вы сохраняете
Cache-aside service + Redis/Postgres Docker Compose setup + race-condition test suite + invalidation design note