Skip to main content

Caching Strategy

Last updated: 2026-05-01

How InventoryAlert uses Redis to reduce external API calls, provide idempotency for SQS processing, and enforce alert cooldowns.

Cache use-cases​

Use-caseWhereKey patternTTLNotes
Quote cacheAPI (StockDataService)quote:{symbol}30sReduces Finnhub calls for hot symbols
Metrics cacheAPI (StockDataService)metrics:{symbol}1hCaches DB-sourced metrics response
Symbol search cacheAPI (StockDataService)search:{query}4hCaches Finnhub search results
SQS idempotencyWorker (ProcessQueueJob)msg:processed:{messageId}24hWritten only after successful processing
Alert cooldownInfra (AlertRuleEvaluator)inventoryalert:alerts:cooldown:v1:{userId}:{ruleId}24hSuppresses repeated notifications for the same rule

Notes and caveats​

  • The Worker currently relies on bounded concurrency (WorkerSettings.MaxDegreeOfParallelism) rather than a strict rate limiter for Finnhub.
  • Cooldown is per-user + per-rule, not per-symbol.
  • Some namespaces exist in CacheKeys (InventoryAlert.Domain.Constants.CacheKeys) but are not yet consistently used by all services (API quote/metrics/search still use simple keys).