Skip to content

[Phase 1] Cache Tags & ProductSummary Denormalization Strategy #68

@syed-reza98

Description

@syed-reza98

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

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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions