How we keep a Laravel log ingest endpoint fast (Valkey buffer, batched ClickHouse writes)
We're building a hosted log tool on Laravel 13, and the part that took the most thought was ingestion. Clients send logs in bursts, sometimes thousands of lines a second, and the endpoint can't sit waiting on a database
We're building a hosted log tool on Laravel 13, and the part that took the most thought was ingestion. Clients send logs in bursts, sometimes thousands of lines a second, and the endpoint can't sit waiting on a database while that happens.
The request does almost nothing
It checks the token, pushes the batch into Valkey (Redis-compatible) and returns a 202. There are no MySQL queries in that path and no queue job per line.
Drainers do the writing
Separate long-running drainer processes, one per buffer shard, claim a batch of 500 to 1000 lines, insert it into ClickHouse, and only acknowledge it after the insert succeeded. Popping first and writing second looks simpler, but it loses lines if the process dies in between.
Replays without duplicates
That raises the opposite problem: if a drainer dies after inserting but before acknowledging, the batch gets inserted again on restart. ClickHouse's insert_deduplication_token handles that. Every batch carries a token, and a repeat with the same token is ignored, so a replay doesn't create duplicates.
Reads start with source and time
Every query filters by source and time range first, because that's what the table's primary key is built on. Without that, ClickHouse has to scan far more than it needs to.
Live tail is the cheap part
After storing a batch, the drainer broadcasts it on a private Laravel Reverb channel and the browser appends the lines. Nothing extra is stored for it.
Happy to go deeper on any of this in the comments. If you want to poke at it, Tailcove is on DevHunt this week and has a free plan: https://devhunt.org/tool/tailcove
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.