Prepared for: Business Requirements Changes (Multi-Category Video Support)
Date: December 10, 2025
Video Count: 58,000 (estimated)
Your new business requirements introduce multi-category support for videos, which requires Redis cache restructuring:
| Component | Change | Impact |
|---|---|---|
| VideoMedia DB | categoryId → categoryIds[] |
Videos can belong to multiple categories |
| Category DB | Remove channelId; add tags (JSON) |
Categories independent; tag denormalization |
| Tag DB | Remove channelId |
Simplified relationships |
| Redis Cache | Add new indexes for multi-category queries | +33 MB memory; 4 new key patterns |
Three comprehensive documents have been created:
REDIS_CACHE_MIGRATION.md - Complete analysis with 8 parts:
REDIS_CACHE_QUICK_REF.md - Quick reference checklist:
REDIS_CACHE_IMPLEMENTATION.md - Step-by-step guide:
| Key Pattern | Type | Purpose | Memory |
|---|---|---|---|
app:video:category:index:{id}:videos |
ZSET | Multi-category video lists | +12.2 MB |
app:video:categories:{id} |
SET | Video-to-categories lookup | +7.5 MB |
app:category:video:count:{id} |
STRING | Video count per category | +80 KB |
app:tag:search:{prefix} |
SET | Tag search index (optional) | +0.5-1 MB |
app:category:tagnames:flat:{id} |
STRING | Flat tag names for search | +400 KB |
| Key Pattern | Changes | Impact |
|---|---|---|
app:video:detail:{id} |
categoryId → categoryIds | All 58K videos affected |
app:category:all |
Remove channelId; tags as JSON; add tagNames | Denormalization |
app:tag:all |
Remove channelId | Simplified |
app:channel:all |
Add categories, tags, tagNames | Denormalization |
| Phase | Tasks | Duration | Effort |
|---|---|---|---|
| 1 | DB schema & migrations | 2-3 days | High |
| 2 | Cache builders (Tag, Category, Channel, Video) | 2-3 days | High |
| 3 | New index builders (3 builders) | 1-2 days | Medium |
| 4 | Invalidation & sync logic | 1 day | Medium |
| 5 | Testing & deployment prep | 2-3 days | Medium |
| Total | 8-12 days |
Recommended Team: 1-2 backend engineers
✅ COMPLETED:
⏳ TODO:
The REDIS_CACHE_IMPLEMENTATION.md includes complete, production-ready code for:
// Updated builders (complete code)
✓ TagCacheBuilder (remove channelId)
✓ CategoryCacheBuilder (add tags JSON + tagNames)
✓ ChannelCacheBuilder (add denormalized data)
// New builders (complete code)
✓ VideoCategoryIndexBuilder (multi-category index)
✓ VideoCategoriesLookupBuilder (video→categories lookup)
✓ CategoryVideoCountBuilder (count cache)
// Integration
✓ Cache sync service updates
✓ Invalidation logic
✓ TTL management
Recommendation: Provision Redis instance with at least 100-120 MB available memory.
Before deploying to production:
Schema Validation
pnpm prisma:generate
pnpm prisma:migrate:dev
Builder Testing
pnpm test:cache --verbose
Redis Memory Check
redis-cli INFO memory
# Verify: used_memory < (max_memory * 0.75)
Cache Hit Rate
redis-cli INFO stats
# Monitor: keyspace_hits, keyspace_misses
Load Test (58K videos)
pnpm test:load --videos=58000 --concurrent=100
A: Yes. A Prisma migration will handle the schema change. Data needs to be populated into the new categoryIds array.
A: Only if code directly references categoryId (single). All queries using categoryIds array need updates. Provide migration script.
A: Approximately 30-60 seconds depending on Redis and database performance. Recommend off-peak timing.
A: Yes. Keep old Redis backup and Prisma migration history. Rollback is reversible within 24 hours.
A: Yes. Any code accessing categoryId must change to categoryIds array. See REDIS_CACHE_IMPLEMENTATION.md for patterns.
A: New keys will coexist with old. Run pnpm cache:rebuild to populate new keys. Old keys can be cleaned up after validation.
After deployment, monitor:
Cache Hit Rate (target: >90%)
keyspace_hits / (keyspace_hits + keyspace_misses)
Memory Usage (target: <75% of max)
redis-cli INFO memory | grep used_memory_human
Query Response Time (target: <100ms)
Monitor from application logs
Index Freshness (target: <2 hours old)
Check video-category index timestamps
✅ Implementation Complete When:
This migration enables flexible multi-category video organization while maintaining high performance. The provided documentation and code examples make implementation straightforward.
Estimated Total Effort: 8-12 days with proper planning
Risk Level: Medium (mitigated with comprehensive testing)
Expected Benefit: 20-30% improvement in query flexibility + slight performance gain
Documents Created:
REDIS_CACHE_MIGRATION.md (8 parts, complete analysis)REDIS_CACHE_QUICK_REF.md (quick reference, checklists)REDIS_CACHE_IMPLEMENTATION.md (step-by-step with code)All files located in: /media/dave/DAVEWORKS/works/fctech.my/box-project/box-repo/box-nestjs-monorepo/
Ready to proceed? Start with Phase 1 as outlined in REDIS_CACHE_IMPLEMENTATION.md