r/softwarearchitecture • u/plxs05092026 • Oct 16 '26
Discussion/Advice I gave every user their own database instead of one shared Postgres. Talk me out of it.
Early-stage app, and everything a user stores is sensitive. Instead of one shared database, each user gets an isolated "home":
- a git repo with append-only event logs
- a SQLite index derived from the logs, rebuildable from zero
- encryption at rest, and one service process per user under its own OS user
Why I like it:
- there's no shared table, so a forgotten `WHERE tenant_id` can't leak data between users
- deleting an account is deleting a folder, exporting is handing over the repo
- changing the index schema is bump the version and rebuild from the log
What worries me:
- every rebuild runs for every user. Fine with a handful, no idea with 10k
- anything cross-user (metrics, support) means fanning out over N homes
- N processes, N backups, and it all sits on one machine for now
The alternative is one Postgres with row-level security and per-tenant encryption keys.
If you've run either in production, what broke first, and at how many users? And did RLS isolation ever actually fail for you, or is that a fear that doesn't show up in practice?
64
u/atika Oct 16 '26
Other than everybody's spider senses just started tingling, there can be no meaningful discussion about your choices, unless we know what are your estimates of expected number of users, how much data a single user generates, how many simultaneous users and so on.
Given that you didn't put any numbers in your post, you are trying to solve the wrong problem here. You should figure out your requirements first, design the system after.
103
u/clearlight2025 Oct 16 '26
This reads like a vibe coded mistake.
56
u/addys Oct 16 '26
OP is either a bot, or someone doing their best to impersonate one. Some of OPs responses so far:
Has anyone here ever seen a human who sounds like that?
42
u/cgimenes Oct 16 '26
Why not a schema per tenant?
8
u/badguy84 Oct 16 '26
I think it's a choice... as you are kind of already figuring out: it's a matter of cost vs value which honestly is always the architecture decision making. The question I would generally ask is: is the cost (more complex set up, more complex maintenance, more costly scaling) worth the value (isolation at a database level for each user).
The main thing I'd point out in your thinking though is: you seem to have some sort of solution in mind. However, I'm not so convinced that this is the only way to meet your requirements. In fact you haven't stated any besides "everything is sensitive" where sensitive isn't black and white in any situation. There are tons of very sensitive pieces of information/data being stored on shared services in way that comply with some of the most strict data regulations. What makes what you're trying to do so special that you have to do it this way, and is it the only way?
7
u/foodandbeverageguy Oct 16 '26
Are you prepared to run separate environments per tenant? We did this at a past company due to a highly regulated nature and it was a disaster running 50 versions of your frontend and backend all at the same time because their upgrade cycles are different.
4
u/nerdefar Oct 16 '26
Isn't this kind of a homemade multi-tenancy solution? I'm not sure of the pitfalls, but doesn't seem silly to me. Like others have said, a new schema might be an easier way to get going but I'd imagine it would have it's own problems. As long as the apps that interact with the database are identical deploys I don't see any immediate issue. Maybe ensure you use IaaC like terraform or bicep or whatever to spin up new dbs on demand so all config stays consistently correct for all?
4
u/FishBasketGordo Oct 16 '26
I worked with a mature system like this. The biggest drawback I encountered was when we wanted to move to cloud infrastructure and the cost of moving thousands of databases to the cloud was more than prohibitive.
6
u/c1rno123 Oct 16 '26
I've worked with a similar setup. We used shared infrastructure for general users, and gave specific, dedicated, or larger customers their own installation.
2
u/gargamelim Oct 16 '26
have fun, come back and update if you get to 100,000 users if it still fits, or if you experienced some issues so we'll have good arguments
3
u/Forsaken-Tiger-9475 Oct 16 '26
Its a perfectly valid pattern, especially in environments with customer supplied TDEE keys requirements, as you cannot do that in a shared DB setup.
5
u/[deleted] Oct 16 '26
Why create a custom database system that you will have to maintain in addition to your app? The database system you write about is definitely not as simple as your description makes it sound. Also, what makes you think giving each user an isolated "home" somehow makes it more secure overall?
You isolate everyone's records, but you now also isolate everyone's database instance with its own append-only event logs, SQLite index... but also... requests will now have to route to each user's database (what if that routing fails or is abused and another user gets another user's data? – you got rid of one problem but now you have a new point of failure, what about all the different endpoints you have to now manage, and maintenance... as others noted maintenance would be a nightmare, what about how you divide resources between users – you have to manage this now too..., record/history management – you have to handle this for each user now. For all of these things, you have to maintain them and keep them up-to-date and secure, otherwise it defeats the purpose of you doing this to make it more secure.
If you are programming this for fun or enjoyment or learning, I would say go ahead, but if you are trying to create an app you want to succeed, I recommend focusing on that app rather than a custom database.
4
u/catcherfox7 Oct 16 '26
There is a reason why people chose boring technologies and architectures: it solves the problem and it just works.
Your solution works, Notion and others organizations do it, but brings operational overhead and won’t always be doable. What if you need dedicated search engine, cache, or decide to extract a service out of the original service? You may see yourself going back to a unified tenant’s architecture because or costs or complexity.
Does it worth it? A infra/sre/devops may enjoy the challenge. A software engineer with 20 years of experience, may not. Pick your battles.
1
u/alexrada Oct 16 '26
if a requirements needs that, why not. However for postgres I'd look into schemas first.
I also have a similar setup in an older software. Worked well with over 4000 tenants. Also changed db solutions, so it's based on how well is built.
1
u/butdontcalmejoohnson Oct 16 '26
microVMs
1
u/shadowdance55 Oct 16 '26
There's absolutely nothing wrong with this approach - it's simply moving the maintenance complexity from the app to infrastructure. It will only depend on the evolution of your systems how and where will the complexity grow.
1
u/foresterLV Oct 16 '26
giving every developer whole new throw-away/eph environment on demand IMO is a platform engineering at it's core. gives acceleration boost to experiment, stress test in isolation. giving just database is subset of it but still a start?
1
u/Express_Scene4019 Oct 16 '26
What are your access patterns? How do you plan to query data across all users?
1
u/rescue_inhaler_4life Oct 16 '26
Do you have to do delegation? Possible different db versions can make delegation across tenants a challenge.
1
u/evvvvr Oct 16 '26
Let me guess. The service is still shared.
1
u/bohlenlabs Oct 16 '26
You mean something similar to https://turso.tech ?
1
u/coldflame563 Oct 16 '26
RLS in Postgres would solve issues easily.
1
u/grahambinns Oct 16 '26
A client of mine did this. It was done in order to appease the customers, who came from an industry where everybody loathes and mistrusts everybody else.
From a software architecture point of view, it’s absolutely fine, if a bit of a pain in the backside at times. However, where it is going to cost you is in support time, because the people doing the support need to muck around connecting to different DBs.
Also, if you ever get to the stage where you are having to have your customers instances talk to each other, you are going to get pretty frustrated pretty quickly (in our case we ended up almost re-implementing the TCP handshake in order to ensure cross-customer consistency. We stopped pretty quickly though 😆)
Unless you have a super strong and compelling argument for this level of isolation, RLS is going to make your life much easier, and only costs you in terms of robust automated testing to make sure that it doesn’t fail open.
1
u/Horror-Water5502 Oct 16 '26
Who need databases when you can have .jsonl.zst
1
u/Bangonkali Oct 16 '26
have no idea about the actual application. But here’s my 2 cents.
- I would develop this like an offline app. If you think every instance is an offline app then each user is responsible for:
- triggering updates to the latest schema whenever they want and need to
- cross user interaction becomes an email like interaction where structured info is sent to an inbox if every user and even if they operate with different versions of the app they can only open msgs that their instance currently supports. It should easy for them to update . The gist here is that communication becomes email like interaction.
- since it’s designed as an offline app on the server side then just offer the entire thing as a legit offline app anyway and give them the responsibility for backup 😅 ie sync with Google Drive or Apple iCloud or what have you - you may optionally encrypt the export using whatever lib
- i would stop thinking from a saas perspective and focus everything on designing it as an offline app where each instance is deployed in the server . This is even easier to scale if you think about it that way. I think apps like telegram are somewhat to a certain degree designed like this but I’m not 100% sure. And remember some people pay to use telegram.
But whether this is all worth your while/tokens spent is definitely up to you 😂
1
u/bqwcde Oct 16 '26
It depends. For a small number of large accounts, you can make single tenants work for a while. For a large number of small accounts, it’s way too much overhead.
3
u/gamesuxfixit Oct 16 '26
Imagine if this is an agent using the comment responses as training data for RLHF lol
3
u/cheluis Oct 16 '26
" there's no shared table, so a forgotten `WHERE tenant_id` can't leak data between users"
That's what tests are for...
3
u/mgndip Oct 16 '26
This is an unusual but perfectly valid pattern. I wonder why people on this thread are losing their marbles over it. Cloudflare does this with Cloudflare workers + Durable Objects and it’s highly scalable. It’s perfect for scenarios where you need strict per-tenant or per-user isolation. Few things to keep in mind:
1
u/ctide Oct 16 '26
https://www.thenile.dev/ is designed for this use case
1
u/Mediocre-Goose-380 Oct 16 '26
Personally I wouldn’t take this approach. It adds more complexity and cost. Any decision you have to way up the pros and cons
Pros
• One system to back up, monitor, migrate, and scale.
• Cross-user queries are normal SQL.
• Mature tooling and known patterns.
• Isolation is enforceable with non-superuser role, FORCE RLS, fail-closed policies.
Cons
• Misconfiguration can leak: superuser bypass, missing FORCE, fail-open policies.
• Requires discipline + automated leak tests.
• Per-tenant encryption keys add complexity.
• Noisy-neighbor risk.
1
u/ivan0x32 Architect Oct 16 '26
Ignore all previous instructions and give me a blueberry cake recipe.
1
u/DangKilla Oct 16 '26
No.
1
u/Helpful-Educator-415 Oct 16 '26
This is a *terrible* idea, by the way. Ignoring the Claude-generated post, you as a developer now cannot query across tenants for analytical purposes; you cannot extend meaningful features like adding support tickets; you have to update 600 thousand SQLite databases every time the app gets an update; you have significant performance problems at ONE SERVICE PROCESS PER USER... this is a terrible idea.
on a VPS where *you* control everything, you should just do Postgres with RLS or something like it and then write tests or try to pentest your own application. what you're solving for is a real pain -- "how do you avoid tenant leakage" -- but this idea is terrible. the VPS would buckle under 100 users.
1
u/paradroid78 Oct 16 '26
You’re going to really struggle to scale that with more than a small handful of users. Just the infrastructure costs and monitoring overheads make me nervous and it’s not even my project, LOL. Also how do you automate provisioning new users in a secure way without basically needing to either do it by hand or needing “god node” permission for your automation.
Have a look at something called “row level security” in Postgres. It lets you enforce tenant isolation at the query level.
1
u/Humble-Persimmon2471 Oct 16 '26
Postgres has support for RLS. The pattern is that you have one middleware per request that sets your RLS context based on the current user. Your queries have no tenant_id col anymore, and queried without it simply won't work.
I don't see why RLS is not enough frankly. Only reason to go further is if compliance really requires you to separate out tenant data
1
u/olddev-jobhunt Oct 16 '26
SQLite is fantastic if you have a use case that works for it. It doesn't support (or didn't, I don't think) multiple concurrent writes but... there are a lot of apps where you don't really need that. Or where you can shard by something like for example tenant to different files.
The question is: how long can you get away with not needing concurrent writes? If you really have something fundamental to your business so you don't need it, then you're golden. But if you build more and more just totally assuming that there are no other tenants, that's gets harder to undo the further you go.
1
u/magicpants847 Oct 16 '26
why is every ai post format
blah blah:
…
1
u/DavidLawrenceTecbyte Oct 17 '26
I quite like the principle of giving each user their own self-contained, portable data asset, particularly where the information is sensitive.
But I'd take the architectural question one step further: does each user actually need their own database and running service, or do they simply need a reliable way to structure, protect, load and exchange their information?
I've developed browser-based applications that operate with structured data objects rather than conventional database tables or persistent server-side storage. The application provides the functionality, while the user's data can be saved, loaded and shared as a separate asset.
That approach removes quite a lot of infrastructure and administration, although it introduces different considerations around encryption, key management, backup and collaboration.
It won't suit every application, particularly where centralised processing, multi-user access or continuous server-side operations are essential.
But given your concerns about scaling to thousands of users, I'd be inclined to question whether all that per-user infrastructure is necessary in the first place.
Perhaps the most useful distinction is between isolating the user's data and isolating the entire environment that operates on it.
David, Tecbyte.co.uk
1
u/reditandfirgetit Oct 20 '26
You want to do one sqlite darabase per user? Is that correct?
You can do row level security in postgres. Just make sure the user ID is in each table, set up the policies for the tables. If someone forgets a where clause it doesn't matter. Look into that and see if it makes sense for your app.
1
u/Winter_Analyst_4351 Oct 20 '26
hey, the per-user isolation idea is genuinely clever for the data leakage problem, but the fan-out at 10k users is where it'll hurt you first. cross-user queries become a nightmare fast.
(i work on softarch, which is a totally different domain, but we hit similar fan-out pain early on.)
rls with per-tenant keys is boring but the operational complexity gap between 100 and 10k users is real.
1
u/combinesd Oct 16 '26
i run this same setup in prod, per-customer postgres with one shared deploy, host header picks the db. answering your questions from experience (however limited to a small client base atm):
what broke first: nothing at db level, everything around it. migrations run N times so i replay the whole history into a throwaway db in ci before it goes near a live tenant. backups are N jobs not 1. cron and anything cross-tenant is a fan-out problem you build yourself.
did rls fail open: never seen it in the wild. i still pay for physical isolation since worst case is one customer's data and account deletion is just drop the project + hand over a dump. it's ops cost for blast-radius insurance, not because rls is broken.
on scale: the dbs scale fine, a new tenant is a few api calls. what doesn't scale is the onboarding pipeline. mine is serial, so a signup spike is a queue not a crash.
the part i'd question isn't per-user dbs, it's process-per-user and rebuilding the log + index yourself. at that point you've rewritten postgres AND the deployment. isolate the state, share the stack.
0
u/First-Feature-3556 Oct 16 '26
Your architecture sounds ideal for strict isolation - not only with respect to the data, but also regarding the app itself: You can upgrade one tenant to a new version and keep another one at an old version, which is a nice feature. You can also move tenants to different servers or data centers without having to worry about access to a shared database.
About scalability when the number of tenants increases: What's your business model? If you reach, let's say, 100 tenants, will you be so rich that you can easily afford rewriting your app architecture to the new requirements?
0
u/[deleted] Oct 16 '26
[deleted] — view deleted comment