Skip to content

Implement a deterministic ETag hashing interceptor for caching immutable historical vault metrics #463

Description

@Damola-Sodiq

Description

Engineer a Fastify plugin that calculates deterministic SHA-1 hashes of historical JSON data to enable aggressive client-side ETag caching.

Architecture & Context

Historical vault performance metrics in tokenized-fractional never change once a ledger closes. However, clients continually re-fetch them. Generating deterministic ETags allows the server to return 304 Not Modified, saving immense bandwidth.

Technical Requirements

  • Serialize outgoing JSON payloads using a strict, alphabetical key-sorting algorithm.
  • Calculate and append the ETag header before flushing the response stream.
  • Intercept If-None-Match headers to short-circuit the execution pipeline immediately.

Acceptance Criteria

  • Unchanged historical data queries return 304 Not Modified.
  • CPU overhead for hashing is mitigated by caching the ETag alongside the DB query.
  • Frontend React Query caches correctly respect the 304 responses without redrawing.

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