Skip to content

backend: implement offline QR session caching with Redis #46

@ShantKhatri

Description

@ShantKhatri

Summary

Product doc section 5.9 specifies Offline QR Mode — QR codes should work fully offline once generated. Implement a Redis-backed QR session cache in the backend so that the public profile data is served from cache, reducing DB load and supporting limited offline scenarios.

Context

The public profile route at apps/backend/src/routes/public.ts currently queries PostgreSQL on every request. Adding Redis caching here allows the profile resolution to serve from cache during poor connectivity scenarios at events.

Tasks

  • ensure Redis plugin is available in the Fastify instance (apps/backend/src/plugins/).
  • in apps/backend/src/routes/public.ts, after a successful DB fetch:
    • serialize the public profile to JSON and store in Redis as profile:<username> with a 5-minute TTL.
    • on subsequent requests, check Redis first; return cached data with X-Cache: HIT header.
  • cache invalidation: when a user updates their profile (PUT /api/profiles/me), delete the profile:<username> key.
  • add cache headers to the HTTP response: Cache-Control: public, max-age=300, stale-while-revalidate=60.
  • add a GET /api/public/:username/qr-session endpoint that returns a pre-signed, short-lived (10 minute) token encoding the profile snapshot — intended for the native app to generate QR codes that don't depend on live connectivity.
  • write tests asserting cache HIT/MISS behavior and invalidation.

Acceptance Criteria

  • Redis cache reduces database calls on repeat views.
  • profile updates invalidate cache immediately.
  • X-Cache header indicates HIT or MISS.
  • QR session endpoint returns a token that can be decoded offline.

Difficulty

advanced — requires Redis integration, cache invalidation strategy, and token design for offline scenarios.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions