Skip to main content
Cache warming is particularly beneficial in scenarios such as e-commerce flash sales, live broadcasts, and major marketing events, where even minor delays can impact user experience and revenue.

How Cache Warming Works

Cache warming operates by:
  1. Identifying Slow Queries: Telemetry data is used to detect high-latency operations that could cause performance bottlenecks. The system prioritizes queries based on P90 latency measurements, ensuring that the slowest queries are targeted for warming.
  2. Building a Manifest: The system prioritizes the slowest queries and compiles them into a manifest for caching. This manifest is stored in the CDN and fetched whenever the router needs it.
  3. Precomputing Query Plans: The cache warmer precomputes and stores query plans in the router, ensuring immediate availability during peak traffic periods. This precomputing occurs at the start of the router, as well as whenever the router restarts due to a configuration update triggered by a subgraph publish.

Configuration & Customization

Enabling Cache Warming

  • The feature is available to enterprise customers via the Cosmo interface.
  • Organizations can activate it at the namespace level to target specific workloads.
  • Users can configure the maximum number of operations for cache warming.
  • Operations are managed using a LIFO (Last-In, First-Out) policy, ensuring the latest operation is added while the oldest is removed once the limit is reached.

Router Configuration

To enable the cache warmer in the router, add the following configuration to your router configuration file:
cache_warmup:
  enabled: true

telemetry:
  metrics:
    attributes:
      - key: "wg.operation.hash"
        value_from:
          context_field: operation_hash
For detailed information on the configuration, click here.

Customization Options

Manually Prioritized Operations Customers can add operations to the cache manually, ensuring critical queries are always warmed. It can be added using wgc.
wgc router cache push <graph_name> -n <namesapce_name> -f <path_to_file>
For detailed information on this command, click here.

Manual Recompute from Studio

Users can manually recompute slow queries from the Cosmo Studio. Currently, recomputation only occurs when a manual operation is added or when the subgraph is published.

In-Memory Switchover Cache Warming

The in-memory switchover feature provides automatic cache persistence across router restarts, ensuring zero cold starts when deploying new configurations or updates.

How It Works

The router can restart due to two reasons, either due to a config change or due to a schema change. Due to the structure of the router internals we have two slight variations on how we handle the in-memory switchover cache warming:
  1. Before Shutdown: In case of config changes, the router extracts all queries from the current plan cache, preserving the “hot” queries that were actively being used.
  2. During Startup: The router with the updated config receives the queries from the previous plan cache and uses them to warm up its plan cache before serving traffic.
  3. Result: The updated router starts with a fully warmed cache, eliminating latency spikes that would normally occur during cold starts.
When using the in memory switchover, the first start will still experience a cold start, as there is no prior populated planner cache. Subsequent restarts will benefit from the in-memory switchover.

When can you use the In-Memory Switchover

The in-memory switchover is a fallback method. Which means if your cosmo account has access to the Cosmo Cloud CDN cache warmer, that will be used instead of the in-memory switchover. However, if this is not the case, the in-memory switchover will be used as the primary cache warming method.
The in-memory switchover won’t be used as a fallback for sources other than the Cosmo Cloud CDN cache warmer, which is the default source.

Configuration

The in-memory switchover is enabled by default when cache warming is enabled. It automatically activates when:
  • Cache warming is enabled on the router configuration (cache_warmup.enabled: true)
  • Cosmo CDN cache warmer is not available or disabled for the account
  • in_memory_switchover_fallback is set to true (default)
cache_warmup:
  enabled: true
  in_memory_switchover_fallback: true  # Enabled by default