Show HN: Trench – Open-source analytics infrastructure (github.com)
https://github.com/frigadehq/trench
I built Trench because the Postgres table we used for tracking events at our startup (http://frigade.com/) was getting expensive and becoming a performance bottleneck as we scaled to millions of end users.
Many companies run into the same problem as us (e.g. Stripe, Heroku: https://brandur.org/fragments/events). They often start by adding a basic events table to their relational database, which works at first, but can become an issue as the application scales. It’s usually the biggest table in the database, the slowest one to query, and the longest one to back up.
With Trench, we’ve put together a single Docker image that gives you a production-ready tracking event table built for scale and speed. When we migrated our tracking table from Postgres to Trench, we saw a 42% reduction in cost to serve on our primary Postgres cluster and all lag spikes from autoscaling under high traffic were eliminated.
Here are some of the core features:
* Fully compliant with the Segment tracking spec e.g. track(), identify(), group(), etc.
* Can handle thousands of events per second on a single node
* Query tracking data in real-time with read-after-write guarantees
* Send data anywhere with throttled and batched webhooks
* Single production-ready docker image. No need to manage and roll your own Kafka/ClickHouse/Nodejs/etc.
* Easily plugs into any cloud hosted ClickHouse and Kafka solutions e.g. ClickHouse Cloud, Confluent
Trench can be used for a range of use cases. Here are some possibilities:
1. Real-Time Monitoring and Alerting: Set up real-time alerts and monitoring for your services by tracking custom events like errors, usage spikes, or specific user actions and sending that data anywhere with Trench’s webhooks
2. Event Replay and Debugging: Capture all user interactions in real-time for event replay
3. A/B Testing Platform: Capture events from different users and groups in real time. Segment users by querying in real time and serve the right experiences to the right users
4. Product Analytics for SaaS Applications: Embed Trench into your existing SaaS product to power user audit logs or tracking scripts on your end-users’ websites
5. Build a custom RAG model: Easily query event data and give users answers in real-time. LLMs are really good at writing SQL
The project is open-source and MIT-licensed. If there’s interest, we’re thinking about adding support for Elastic Search, direct data integrations (e.g. Redshift, S3, etc.), and an admin interface for creating queries, webhooks, etc.
Have you experienced the same issues with your events tables? I'd love to hear what HN thinks about the project.
38 comments
[ 2.9 ms ] story [ 113 ms ] threadWhy should I use it? What are the unique selling points of your project?
So TLDR, if you're at a smaller scale (<1M MAUs), you probably will be fine just using a table in MySQL or Postgres. If you have a lot of traffic and users, you will need something like Trench that uses Kafka and ClickHouse.
I'm interested in your project can do for me, my project(s), team/company. There is a reason that most of the internet still uses PHP and old technologies. Because they focused not on the latest tech but on solving problems for others.
The project looks cool, but tell us the usecases.
The question remains: Why choose Trench over just using Kafka and Clickhouse or any other message queue and columnar database / big data base?
If the goal of the post and the landing website is to entice people to use the tool, then answering these questions is important. If what is being discussed seems obvious, then who is the target demographic? Because they already know the space, use alternatives or have built their own.
My YC app: Dropbox - Throw away your USB drive
https://news.ycombinator.com/item?id=9224
My comment is feedback to better pitch the project with the goal of attracting more users.
The Dropbox comment, in contrast, is a mean-spirited criticism that just lists alternatives.
It's built on tech known for handling very large amounts of traffic, which answers the how after the what.
2) any admin interface or just the rest API?
3) a little bit on the clickhouse table and engine choices?
4) stats on Ingesting and querying tbe same time
5) node doesn't support the clickhouse TCP interface. This was a major bottleneck even with batching of 50k events (or 30 secs whichever comes first)
6) CH indexes?
7) how are events partitioned to a Kafka partition? By userId? Any assumptions on minimum fields
Will try porting our in-house marketing automation backend (posthog frontend compatible) to this and see how it goes (150M+ events per day)
Kudos all around. Love all 3 of your technology choices.
1) All data is partitioned based on the "instanceId" of events (see `instanceId` here: https://docs.trench.dev/api-reference/events-create). Instance IDs are typically a logically meaningful way of separating users (such as by company/team/etc.) that allows for sharding the data across nodes.
2) Yes, this the number 1 thing on our roadmap right now (if anyone is interested in helping build this, please reach out!)
3) We're using the Kafka engine in ClickHouse for throttling the ingestion of events. It's partitioned by instanceId (see #1) for scaling/fast queries over similar events.
4) My benchmarks in production showed a single EC2 instance (16 cores / 32 gb ram) barely working at 1000+ inserts / second with roughly the same amount of queries per second. Load averages 0.91, 0.89 0.9. This was in stark contrast to our AWS Postgres cluster which continued to hit 90%+ CPU and low memory with 80 ACUs, before we finished the migration to Trench.
5) We seemed to solve this by running individual Node processes on every core (16 in parallel). Was the limit you saw caused by ClickHouse's inbound HTTP interface?
6) Right now the system uses just a default MergeTree ordered by instanceId, useId, timestamp. This works really well for doing queries across the same user or instance, especially when generating timeseries graphs.
7) I am still trying to figure out the best Kafka partitioning scheme. userId seems to be the best for avoiding hot partitions. Curious if you have any experience with this?
Let us know how the migration goes and feel free to connect with me (christian@trench.dev).
Because the next step would be trying to run some cron for a user or event based trigger based on the events.
And the only way to avoid multiple machines doing the same work / sending the same comms - would be to push all users events to a partition. This way with multiple workers you don't have the risk of duplicate processing.
https://clickhouse.com/blog/asynchronous-data-inserts-in-cli...
That being said, Kafka has in my experience come in super handy again and again, simply because it adds an incredible extra layer of fault tolerance when running at scale, including the ability to replay events, replicate, fail over, etc. I'd be nervous about letting the amount of throughput we receive directly interface to ClickHouse (though I'd be excited to run an experiment with this).
example over user+invoices: i.e. there are things that have to come in exact order (e.g. activity on certain invoice), and there are things that can move around (i.e. processing those, timewise), being independent from one another (different invoices' activities, wholesale). But when same user acts on different invoices, then whole one-user-activity should be in exact order.. not just invoice-activity
At 1M events/day that's $7.5/day. Decent
At 15M, $75/day
Cost for 150 million S3 PUT requests per day of 25KB each would be $750/day, assuming no extra data transfer charges.
With clickhouse you won't get charged per read/write
Even if you compress N objects through spark/etc your starting point would be the large number of writes first. So that doesn't change. The costs would be even larger considering even more medium sized PUT's that double the storage, add N deletes potentially. Have also heard that Athena, presto etc charge based on rows read.
Auto-archiving to cloud for Kafka (Confluent, AWS KMS, etc.) / ClickHouse (ClickHouse Cloud, etc.) is definitely high on the roadmap.
Also, minor issue in your docs. There is an extra comma in the sample JSON under the sample event. The fragment below:
I had to remove that comma at the end.We (Frigade.com) actually use Posthog as well as Trench in production. Posthog powers all our website analytics. Trench powers our own SDK and tracking scripts we ship to our own customers.
I actually tried to spin up Posthog originally before building Trench, but there was just way too much overhead and "junk" we didn't need. I would need to strip out so many features of their Python app, it would eventually be faster to build a clean solution in Typescript ourselves.
[1]: https://posthog.com/docs/self-host
Unfortunately not my experience. Possibly not well promoted, but trying to get vscode copilot to generate anything involving semi-basic joins fall quite flat.