Prompt
How do I keep application logs for 90 days and still search them fast?
Latest observation
To keep application logs for 90 days and still search them quickly, use a setup that separates hot search storage from long retention storage, and make the logs easy to query.
Recommended approach
1. Use a log platform built for indexed search
Store logs in a system like:
- Elasticsearch / OpenSearch
- Splunk
- Datadog Logs
- Loki with a good query strategy
- ClickHouse for very high volume, SQL-style analytics
These systems let you search by fields like:
- timestamp
- service name
- host/pod
- log level
- request ID / trace ID
- user ID
- error code
Fast search depends much more on structured fields than on plain text.
2. Write logs as structured JSON
Example:
{
"timestamp": "2026-10-28T10:15:30Z",
"level": "error",
"service": "payment-api",
"env": "prod",
"request_id": "abc123",
"user_id": "u789",
"message": "Card authorization failed",
"error_code": "PAY_402"
}
This makes it much faster to filter by fields instead of scanning raw text.
3. Partition by time
Store logs in daily or hourly indices/partitions.
Example:
logs-2026-10-01logs-2026-10-02
This helps the system skip most data when you search a date range.
Best practice:
- Hot tier: recent logs on fast SSDs for quick searches
- Warm tier: older logs on cheaper storage
- Cold/archive tier: rarely used logs, compressed and slower
4. Use retention and lifecycle policies
Set up automatic aging:
- keep logs fully searchable for 90 days
- move older logs to cheaper storage if needed
- delete automatically after 90 days
This is often called:
- ILM in Elasticsearch/OpenSearch
- retention policies in Splunk/Datadog/Loki
A common pattern:
- Days 0–14: hot
- Days 15–60: warm
- Days 61–90: cold
- Delete after 90 days
5. Index only the fields you need
Too many indexed fields can slow ingestion and increase cost.
Index:
- timestamp
- service
- severity
- request_id
- trace_id
- environment
- error code
Avoid indexing large free-text blobs unless necessary.
6. Keep logs compressed but searchable
Use compression to reduce storage cost, but make sure your tool can still query efficiently.
Good options:
- compressed indices
- columnar storage
- object storage + query layer
- tiered storage
7. Add correlation IDs
For fast debugging, include:
request_idtrace_idsession_id
Then you can search a single request across multiple services instantly.
A practical architecture
If you’re building this yourself:
- Apps write JSON logs
- Logs ship via Fluent Bit / Vector / Filebeat
- Store in:
- OpenSearch/Elasticsearch for recent searchable logs
- S3/GCS/Azure Blob for long-term archive
- Use ILM to move logs between tiers and delete at 90 days
This gives:
- fast search for recent logs
- lower cost for older logs
- automatic cleanup
If you want the simplest answer
For most teams, the best balance is:
- Structured JSON logs
- Daily index rotation
- Hot/warm/cold tiers
- Retention policy for 90 days
- Search by indexed fields and correlation IDs
If you want, I can also suggest:
- a low-cost architecture for 90-day retention, or
- a specific setup for Elasticsearch/OpenSearch, Loki, or Splunk.