Prompt
I’m building an app with dozens of services how should traces be stored
Latest observation
For an app with dozens of services, don’t store traces in each service. Centralize them in a distributed tracing backend and treat services as trace producers only.
Recommended approach
1) Use a standard trace format
Instrument every service with OpenTelemetry and propagate context across service boundaries using:
trace_idspan_id- W3C Trace Context headers (
traceparent,tracestate)
This makes traces correlate cleanly across all services.
2) Send traces to a collector, not directly to storage
Each service should export spans to an OpenTelemetry Collector or similar agent/sidecar.
Flow:
- Service emits spans
- Collector receives, batches, filters, samples, enriches
- Collector forwards to trace storage backend
This reduces load on app services and gives you a control point for sampling and processing.
3) Store traces in a backend designed for high-cardinality time-series
Use a tracing system like:
- Jaeger
- Grafana Tempo
- Zipkin
- Datadog / New Relic / Honeycomb if using SaaS
Backend choice depends on scale and retention needs.
4) Partition storage by trace ID and time
Traces are usually queried by:
- trace ID
- service name
- operation name
- time range
- error status
A good backend indexes metadata lightly and stores the full span data in cheaper object storage or an optimized column store.
Common pattern:
- Hot index for recent searchable metadata
- Cold object storage for full trace bodies
- Optional downsampling for old traces
5) Keep retention policy strict
Do not keep all traces forever. Set:
- short retention for full-fidelity traces, e.g. 3–30 days
- longer retention for sampled/aggregated metrics
- higher sampling on success paths, lower on noisy internal requests
6) Sample intelligently
With dozens of services, storing every trace can get expensive fast. Use:
- head sampling for baseline cost control
- tail sampling to keep error/slow traces
- adaptive sampling for high-volume endpoints
A common strategy:
- 100% of errors
- 100% of slow traces
- 1–10% of normal traffic
Practical storage model
A typical span record includes:
- trace ID
- span ID
- parent span ID
- service name
- operation name
- start timestamp
- duration
- status/error
- attributes/tags
- events/log links
- resource metadata
Store spans as append-only records. Reconstruct traces by grouping spans with the same trace ID.
What not to do
- Don’t write trace data into the primary application database
- Don’t store traces only in logs
- Don’t let every service manage its own trace store
- Don’t keep unlimited full-fidelity traces
If you want a simple default architecture
Use:
- OpenTelemetry in every service
- OpenTelemetry Collector
- Grafana Tempo or Jaeger
- Object storage + short-lived index
- Tail sampling for errors/slow requests
If you want, I can also give you:
- a reference architecture diagram,
- a schema for storing spans, or
- a recommended setup for Kubernetes / AWS / GCP.