šŸš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
šŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

Untitled Lesson

⚔ Total XP: 0|šŸ’» backend XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Select an unlocked node to view details root

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

The Error //

Forgetting to invalidate the cache on delete, only handling update

// Wrong: delete forgets to clear the cache const deleteProduct = async (id) => { await db.products.delete(id); // missing: await redis.del(`product:${id}`); }; // Correct const deleteProduct = async (id) => { await db.products.delete(id); await redis.del(`product:${id}`); };

The Solution //

Teams often wire up cache invalidation for updateProduct() but forget deleteProduct() entirely, so a deleted item keeps 'existing' in the cache and gets served to users until its TTL finally expires. Every code path that mutates a row — create, update, and delete — needs the matching cache invalidation call, not just the most common one.

The Error //

Rebuilding a hot cache key with no lock, causing a thundering herd on expiry

// Wrong: every concurrent miss queries the DB let data = await redis.get('home'); if (!data) { data = await db.query(); await redis.set('home', data); } // Correct: only one request rebuilds, others wait if (!data) { const locked = await redis.setnx('lock:home', '1'); if (locked) { data = await db.query(); await redis.set('home', data); await redis.del('lock:home'); } else { await sleep(50); data = await redis.get('home'); } }

The Solution //

When a popular key's TTL expires, every concurrent request sees a cache miss and hits the database at once, which can take an otherwise healthy database down in seconds under real traffic. Use a lock (e.g. Redis SETNX) so only the first request rebuilds the cache while the rest wait briefly and re-read the now-populated cache.

Continue Learning