-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Priority: P0 (Critical)
Phase: 1 - E-Commerce Core
Estimate: 2 days
Type: Story
Context
Implement targeted cache invalidation using Next.js cache tags plus a denormalized ProductSummary record to accelerate listing, cart, and merchandising queries.
Scope
- Denormalized table: ProductSummary (id, productId, storeId, title, price, active, inventoryAvailable, primaryImageUrl, updatedAt)
- Populate/refresh on product change, inventory change, price change
- Cache tags:
product:{id},store:{storeId}:products,inventory:{productId} - Server components query ProductSummary for list views instead of full Product joins
- Invalidation function:
revalidateProduct(productId)triggers relevant tags - Background reconciliation job (daily) to ensure summary consistency
Acceptance Criteria
- Product create/update triggers ProductSummary mutation & cache tag revalidation
- Inventory change updates ProductSummary.inventoryAvailable within < 500ms
- Listing pages use ProductSummary only (no N+1 full product fetch)
- Stale reads after update < 5s (eventual consistency window)
- Reconciliation job logs discrepancies count (should trend to 0)
Data Model (Draft)
model ProductSummary {
id String @id @default(cuid())
productId String @unique
storeId String
title String
price Int
active Boolean @default(true)
inventoryAvailable Int @default(0)
primaryImageUrl String?
updatedAt DateTime @updatedAt
@@index([storeId])
}Dependencies
- Relies on core Product & Inventory models
- Supports performance optimization for marketplace & multi-channel ([Phase 3] Epic: Multi-Channel Sales #35, [Phase 5] Epic: Advanced Reliability #37)
Metrics
- Product list query latency reduction > 30%
- Consistency discrepancy rate < 0.1%
Testing Checklist
- Product update reflected in ProductSummary & listing
- Inventory adjustment updates summary
- Cache tag revalidation removes stale page
Risk
Performance & correctness impact (score: 15). Enables scalable product browsing.
References
- docs/GITHUB_ISSUES_COMPARISON_ANALYSIS.md (cache tag gap section)
Copilot