Hacker News new | ask | show | jobs
by pgm8705 1268 days ago
I'm curious how one goes about handling the need to query data across customers with the one-database-per-customer pattern.
4 comments

It depends on what you're trying to do. If you're trying to query revenue then that's usually stored in a third-party system like Stripe. If you're tracking metrics then those can be aggregated into a time series database like Prometheus and viewed through Grafana.

It's definitely a trade-off. Isolation is pretty compelling for a lot of mid-market and enterprise customers but it does come at a cost of making it a pain to query across customers. But then again, that's kinda the point. :)

You can attach multiple dbs and join across them and it works very well. The default limit is ten and I think the max is a hundred so there's definitely a limit. But if you really needed to do more I can think of some workarounds.
Pretty simple with the built-in command

ATTACH customer145.sqlite as customer145; ATTACH customer2.sqlite as customer2;

Then query the attached tables.

with a script