Reader/writer split

One writer ingests into a shared bucket, and a pool of readers serves queries from it. Queries scale without touching ingest.

How it works

The writer owns the database's one shard, holds it with a Kubernetes Lease, and flushes to object storage every flushIntervalSeconds. Readers open the same shard read-only from the bucket and follow the writer's flushes, so queries trail ingest by about that interval. Readers keep no state beyond their cache, so they can be added, removed, or autoscaled at any time.

Deploy

It is a Sharded resource with one writer, and needs a bucket every pod can reach: grant S3 access first. Hover a field to see what it does:

metrics.yaml
1apiVersion: telemetry.plural.sh/v1alpha12kind: Metrics3metadata:41  name: metrics52  namespace: telemetry6spec:73  mode: Sharded84  config:95    retention: 60d10    storage:116      path: metrics12      objectStore:137        type: Aws14        aws:158          region: us-east-1169          bucket: acme-telemetry17    write:1810      flushIntervalSeconds: 1019  writer:2011    replicas: 12112    resources:22      requests: { cpu: "1", memory: 2Gi }23      limits: { memory: 4Gi }2413    cacheVolume:25      persistentVolumeClaim:26        accessModes: [ReadWriteOnce]27        resources: { requests: { storage: 20Gi } }28  reader:2914    replicas: 23015    cacheVolume:31      emptyDir: { sizeLimit: 20Gi }3216    autoscaling:33      enabled: true34      maxReplicas: 635      targetCPUUtilizationPercentage: 70
  1. 1name
    Also names the ServiceAccount the IAM role binds to, and the metrics-writer and metrics-reader Services (just metrics in Standalone mode).
  2. 2namespace
    The Kubernetes namespace the pods run in. Tenant namespaces for your data are separate and come from NamespaceAuthentication resources.
  3. 3mode
    Standalone (the default) runs one pod that reads and writes. Sharded runs a writer StatefulSet and one reader StatefulSet per storage shard, which scale independently.
  4. 4config
    Rendered into the server's config file. The operator rolls the pods when it changes.
  5. 5retention
    How long data is kept, counted from ingestion, as 60d, 2w or 36h. Default 60d.
  6. 6path
    Object-key prefix inside the bucket; shard suffixes are appended. Must match the prefix in the IAM policy. Default metrics.
  7. 7type
    Aws, Gcp, Azure, Local or InMemory. With Aws and no key references, the pod uses its Pod Identity credentials.
  8. 8region
    Bucket region. Add endpoint (and allowHTTP if needed) for S3-compatible stores such as MinIO.
  9. 9bucket
    Can be shared by all three databases, as long as their path prefixes differ.
  10. 10flushIntervalSeconds
    How often writers flush to object storage, and so how far readers can lag behind. Default 10.
  11. 11replicas
    Writer count, which is also the storage shard count. Raise it at any time; new shards take writes from the next aligned hour. It cannot be lowered.
  12. 12resources
    Defaults to 250m CPU and 512Mi memory requests with a 2Gi limit. Budget for the write buffer: 64 MiB per shard, plus up to two frozen buffers being flushed.
  13. 13cacheVolume
    Mounted at /var/cache/metrics as the disk tier of the block cache (512 MiB RAM and 10 GiB disk by default). A PVC keeps it warm across restarts. Set exactly one of emptyDir or persistentVolumeClaim.
  14. 14replicas
    Replicas per reader group. Each storage shard gets its own group, which opens only that shard; any reader answers any query by asking the other groups over gRPC. Default 2 in Sharded mode. Scale freely, or set autoscaling to scale each group on CPU.
  15. 15cacheVolume
    An emptyDir is enough: a restarted reader refills its cache from the bucket.
  16. 16autoscaling
    Adds a HorizontalPodAutoscaler per reader group. minReplicas defaults to replicas; scale on targetCPUUtilizationPercentage or targetMemoryUtilizationPercentage.

Apply it with kubectl apply -f metrics.yaml, then add credentials and connect your tools to the metrics-writer and metrics-reader Services.

bash
kubectl -n telemetry get metrics
# NAME   MODE      READY   AGE
# metrics Sharded   True    2m

kubectl -n telemetry port-forward svc/metrics-reader 8080 &
curl -u grafana:"$PASSWORD" http://localhost:8080/read/ns/payments/api/v1/labels

Operating it

  • Queries: readers scale on CPU between replicas and maxReplicas. Raise reader memory and cache for heavier queries.
  • Writer restarts: while the writer is down, ingest fails and readers keep serving what was flushed. The restarted pod takes its shard back once the Lease expires (spec.config.sharding.leaseDurationSeconds, 15 by default).
  • Outgrowing one writer: raise spec.writer.replicas to become a sharded deployment.