traqq
High-performance event metrics system. Records JSON events into pluggable storage backends and queries them back with type-aware aggregation.
Rust rewrite of trk2 (CoffeeScript/Redis). Same concepts, better performance, backend-agnostic.
What it does
You send JSON events. Traqq generates four types of metrics from each event:
- bmp (bitmap) - unique counts via HyperLogLog (e.g., unique IPs)
- add - counters per field value (e.g., purchases per event type)
- adv - value accumulators with sum/count summaries (e.g., revenue per campaign)
- top - sorted leaderboards (e.g., top geos by volume)
Compound keys are auto-generated from property pairs, so event + geo automatically creates event~geo metrics without extra config.
Quick start
As a library
use *;
let config = TraqqConfig ;
let traqq = new.unwrap;
// record
traqq.record.unwrap;
// query last 7 days
let result = traqq.query_days.unwrap;
// find specific metrics
let adds = result.find;
// shorthand
let top_geos = result.find_str;
As a server
# start with in-memory storage
# start with redis
# record events
# query last 10 days
TCP protocol
The server accepts newline-delimited JSON over TCP (default port 9876):
Responses:
Installation
[]
= "0.2.0"
# with redis support
= { = "0.2.0", = ["redis-storage"] }
Storage backends
| Backend | Feature flag | Use case |
|---|---|---|
| Memory | default | Testing, embedded, ephemeral |
| Redis | redis-storage |
Production, persistence |
The Storage trait is public. Implement it to add your own backend.
Configuration
TraqqConfig
Key format
prefix:type:bucket:timestamp:pattern
Examples:
myapp:bmp:d:1700000000:ip
myapp:add:d:1700000000:event
myapp:adv:d:1700000000:amount:event~geo
myapp:adv:d:1700000000:amount:event~geo:i (summary: sum + count)
myapp:top:d:1700000000:geo
myapp:k:d:1700000000 (key tracking set)
Performance
Apple M2 Max, single thread:
- 40,000+ events/sec processing
- ~6.7MB for 5,000 events
- Multi-threaded recording supported (Storage trait is Send + Sync)
Project structure
src/
lib.rs # core types, Traqq struct, query system
constants.rs # defaults
utils.rs # sanitize, timezone, validation
server.rs # TCP server (JSON-line protocol)
client.rs # TCP client
main.rs # CLI
tests.rs # 49 tests
storage/
mod.rs # Storage trait + tests
memory.rs # in-memory backend
redis.rs # redis backend (feature-gated)
Tests
# default (44 tests, no external deps)
# with redis integration tests (49 tests, requires running redis)
License
MIT