द लैब्स / 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 Method
map → decide → prove
आप रखते हैं
Cache-aside service + Redis/Postgres Docker Compose setup + race-condition test suite + invalidation design note