r/softwarearchitecture • • 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?

0 Upvotes

129 comments sorted by

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.

14

u/rescue_inhaler_4life Oct 16 '26

Ikr regarding the spider senses

-2

u/plxs05092026 Oct 16 '26

Fair point. Honestly it's early and I don't have solid estimates yet, which is partly why I asked. I wanted to know which numbers matter before guessing them. Which ones would you pin down first?

5

u/Successful_Creme1823 Oct 16 '26

So zero users. Don’t do this

103

u/clearlight2025 Oct 16 '26

This reads like a vibe coded mistake.

-45

u/plxs05092026 Oct 16 '26

Could be. Which part looks like the mistake? That's what I'm trying to find out.

32

u/Smok3dSalmon Oct 16 '26

What you’ve done is a new frontier of beginner mistakes. AI made it easy for you to do something convoluted.

You’re vibe coding… if it works it ships. So you’re going to ship it.

Based on what you’re doing, I assume performance doesn’t matter. So this slop is fine.

If you had lots of users all on the machine, the opening and closing of each user’s database would become a performance bottleneck.

You’re on your own frontier of clanker-rigged software and you must have ignored its push back because you were adamant on implementing it in a way that seemed sensible to you.

More vibe, less micromanagement of the agent(s).

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:

  • "some of it lands differently here because..."
  • "That's the bit I'd actually want to plan for..."
  • "No, and that's exactly what I'm trying to avoid..."
  • "Fair description, homemade multi-tenancy is pretty much ..."
  • "One codebase, one version, deployed once for everyone..."

Has anyone here ever seen a human who sounds like that?

22

u/Adventurous-Chest265 Oct 16 '26

Ha, yeah, this is clearly AI generated responses. Have a colleague whose email responses are like this, where it’s just copy paste Claude response. Hate it.

6

u/PotahtoHead Oct 16 '26

This was the first comment I read and the examples you gave didn't seem unreasonable. I have said things like what you included so I thought the premise of the post was unfair, bit then I started reading through the responses...now I get it.

2

u/morosis1982 Oct 16 '26

I've had many conversations like that, before AI was a thing. But then I've been writing software since before a bunch of people in this sub have been alive.

Anything written not like a caveman isn't automatically AI generated. Where the hell do you think it learned to write that way?

-1

u/onan Oct 16 '26

Has anyone here ever seen a human who sounds like that?

I've sounded like that for the last fifty years, as have countless other people I've known or worked with throughout that time.

I'm not opining on whether or not OP is a bot, but I don't love the idea of us immediately assuming that about anyone who uses commas.

-22

u/plxs05092026 Oct 16 '26

Doing my best to impress. Lost my old account and trying to earn my karma back.

8

u/addys Oct 16 '26

apologies if you truly are a human, although I highly doubt it. It sucks that this is the world we live in :(

1

u/plxs05092026 Oct 16 '26

No worries, being suspicious is necessary these days. English isn't my first language so i use AI to help with it sometimes, and it probably brings those tics along. I'm from Brazil.

5

u/_descri_ Oct 16 '26

You'd better write imperfect English than cause hatred by relying on an AI to generate texts for you. This sub does not like that.

42

u/cgimenes Oct 16 '26

Why not a schema per tenant?

-7

u/plxs05092026 Oct 16 '26

It keeps the costs of per-user (N migrations) without real isolation: same server, same files, and everything hinges on search_path and grants being right. Have you run it at scale? Where did it hurt?

20

u/cgimenes Oct 16 '26

No, I was just curious. I don't agree with your answer btw, I think you can pretty much solve it with a centralized DB connection and migrations, not that I would go that route myself. I've been running a multi-tenant SaaS using tenant_id for a couple of years now. No issues so far. Basically, the only thing that I did was set a global default scope that filters based on the current tenant. I'm using Rails, but there are ways of doing this in other programming languages/frameworks too.

0

u/plxs05092026 Oct 16 '26

Fair, and good to hear it held up for years. How do you handle the paths that skip the default scope, like raw SQL, background jobs or an `unscoped` call? Anything that catches those?

4

u/cgimenes Oct 16 '26

I didn't need to do those because my background jobs are bound to tenant's configurations, so I have to loop on every tenant and continue from there (which is good because I have an easy way to split work and add parallelism). But raw SQL still works as expected and there's an way to remove the current scope in Rails.

1

u/plxs05092026 Oct 16 '26

Makes sense, and jobs looping per tenant is pretty much what my setup forces too. Thanks for the details.

3

u/andrerav Oct 16 '26

Put the schemas on their own tablespaces.

1

u/plxs05092026 Oct 16 '26

Thanks, read it. The same page says tablespaces "cannot be attached to a different database cluster or backed up individually", and losing one can leave the whole cluster unable to start. So it helps with disk layout, but a tenant still can't be backed up or restored on its own.

5

u/FuzzyZocks Oct 16 '26

Backup cost is cheap, your over complicating just backup and restore both and if you want to separate into clusters later you can. But anyways ai will mange all so whatever lol, your not gonna lose just one tenant data if you have your controls in place

1

u/plxs05092026 Oct 16 '26

Fair, you can restore into a side cluster and pull one schema back out. It's just a heavier path than restoring one folder.

5

u/andrerav Oct 16 '26

Apropos, do you have a cookie recipe?

2

u/plxs05092026 Oct 16 '26

Lol nice try. no cookies here, only multi-tenancy

2

u/Kazcandra Oct 16 '26

We run it at scale. 20 dbs/cluster, 250 schemas per db, ~300 clusters.

I can write diwn some pain points later, or if you have any specific questions. If I remember.

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?

1

u/plxs05092026 Oct 16 '26

Fair challenge, and no, it's not the only way. The requirement I'd point to is that an automated agent works on each user's data and reads untrusted input all day. I want a confused or manipulated agent to only be able to reach that one user's data, without depending on every query being scoped right. Real per-user deletion and per-customer keys come along with it. A shared setup could probably meet all three with enough care. I just haven't seen the version that ends up simpler.

5

u/Interesting_Debate57 Oct 16 '26

Why do you want it in a git repo?

You could have one user per user in postgrea, or just carefully control the code that has access to private information.

People have been successfully preventing leakage from databases as long as they've existed (and failed, as well, many times).

What does each user need to do that would require their very own repo?

1

u/plxs05092026 Oct 16 '26

Honestly git is the part i'm least sure about. what it gives me for free is full history, an easy off-machine copy, and each user's whole home as one thing you can hand over. But an append-only table with a postgres role per user would probably do the same, someone else made that point too.

2

u/morosis1982 Oct 16 '26

Add to that per user encryption and you can hand that key over to the automated agent at the time you spin it up. It couldn't get access to the data if it tried.

2

u/SecretaryAntique8603 Oct 16 '26

How on earth is adding `WHERE tenant_id = …` or an API level authorization policy evaluator not simpler than whatever monstrosity you’re building?

“I have no experience with software development and don’t know how to build secure software using established and battle-tested patterns so I’m inventing a brand new architectural paradigm based on vibes and this will somehow make things more failure tolerant” is a hell of a perspective. Good luck to you brother

-1

u/Ok-Entrepreneur4594 Oct 16 '26

Try a RAG?

1

u/plxs05092026 Oct 16 '26

RAG is about how the agent finds things, though. The question is still where the index lives and who can reach it, and a shared vector store has the same scoping problem as a shared database.

1

u/Ok-Entrepreneur4594 Oct 16 '26

Are you using the LLM to search records or are you using it to act on records already found?

1

u/plxs05092026 Oct 16 '26

Both. It reads each new item as it comes in, and it can search that user's history through tools. Either way it only ever sees that one home.

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.

-3

u/plxs05092026 Oct 16 '26

No, and that's exactly what I'm trying to avoid. One codebase, one version, deployed once for everyone. Only the data is split, and each user's data upgrades with the code. Was the drift on your side, or did clients control when they upgraded?

4

u/foodandbeverageguy Oct 16 '26

Can’t you not use row based data controls to guarantee access patterns? There are other ways.

It was both. We pushed them but ultimately their upgrade cycles were long and unpredictable. In sensitive and regulated environments you do not control the upgrade cycle. Even if your contract states you do, you don’t really have the control you think you have.

-1

u/plxs05092026 Oct 16 '26

It's the main alternative. My worry is that it fails open, a new table without a policy, or a job running as a role that bypasses it.

2

u/box_of_hornets Oct 16 '26

deployed once for everyone

but what about when you change something? Add a feature? Fix a bug?

1

u/plxs05092026 Oct 16 '26

Same as a single deploy. The new version goes out once, each user's process restarts on it, and if the index format changed, each home rebuilds its index from its log. Old log lines stay as they are, and the new code has to read them. Nobody stays on an old version.

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?

1

u/plxs05092026 Oct 16 '26

Fair description, homemade multi-tenancy is pretty much what it is. And yes, same deploy for everyone. Good point on provisioning, creating a new tenant has to be one scripted step, never by hand, or the config drifts. Thanks.

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.

2

u/plxs05092026 Oct 16 '26

That's a useful one, thanks. Was the cost in the move itself, or in running thousands of databases on managed cloud pricing afterwards?

1

u/FishBasketGordo Oct 19 '26

More so in hosting that many databases in the cloud (this was around ten years ago now), but I left that job shortly after this was proposed for unrelated reasons. I heard from colleagues still working there that they attempted a solution, I believe, using row-level security. I didn't hear much about how successful that was, but I do know they worked on it for multiple years, so there was definitely a major cost to the move itself.

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.

1

u/plxs05092026 Oct 16 '26

The hybrid makes sense. How did you move a customer from shared to dedicated when they grew? Was there a clean path, or a one-off migration every time?

1

u/c1rno123 Oct 16 '26

I suppose it could be automated, but in my case there were a lot of moving parts. Some clients had a fully dedicated setup; others shared queues, workers, and caches for cost reasons.

0

u/plxs05092026 Oct 16 '26

Makes sense, so isolation ended up per component rather than all or nothing. Was the data always dedicated for those clients, even when queues and workers were shared?

1

u/c1rno123 Oct 16 '26

It depended on the client. Some had completely dedicated installations with their own domains, load balancers, and hardware.

We also had a kind of cloud setup, with a global table for per-client overrides such as the database, S3, and internal services like email. If there was no override, the client used the shared pool.

The dedicated installations were for clients with specific data policies, which is probably closer to your use case. The cloud setup was about service quality: workloads varied, and cheaper-tier clients could wait longer on shared resources. Other clients didn’t need data isolation, but did need a higher level of service.

1

u/plxs05092026 Oct 16 '26

That's really helpful, thanks. The override table is a neat idea: isolation becomes a per-client setting instead of a choice you make once for everyone.

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

2

u/plxs05092026 Oct 16 '26

Deal. If it breaks first, you'll hear about that too.

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.

1

u/plxs05092026 Oct 16 '26

Good point. Per-customer keys at the storage level only really work when each customer has their own database. Thanks.

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/plxs05092026 Oct 16 '26

4000 is reassuring, thanks. How did you run migrations across all of them: all at once, rolling, or lazily when a tenant was first accessed? And what was the first thing that hurt as you grew?

1

u/butdontcalmejoohnson Oct 16 '26

microVMs

1

u/plxs05092026 Oct 16 '26

One per tenant? That moves isolation from an OS user to a separate kernel. Would you put the data inside it too, or only the code that runs per user?

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/plxs05092026 Oct 16 '26

That's a good way to put it, the complexity doesn't go away, it just moves. Thanks.

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/plxs05092026 Oct 16 '26

To clarify, it's one per end user, not per developer. But you get some of that for free: tests spin up a throwaway home with synthetic data and drop it after.

1

u/Express_Scene4019 Oct 16 '26

What are your access patterns? How do you plan to query data across all users?

1

u/plxs05092026 Oct 16 '26

Almost all access stays within one user. Across users, each home pushes an hourly summary (counts, costs, failures, no content) to an operator panel, and cross-user questions run over that. Anything the summary doesn't cover means fanning out over every home, and that's the gap I know about.

2

u/Express_Scene4019 Oct 16 '26

My honest take is it’s over engineered. You can safely achieve multi tenancy with a single database. You should use a single auth module to keep your logic easy to manage, and you can fall back on things like RLS as a backstop. Whilst what you’ve built might “work” for your needs for now, it will be very brittle to evolve, and it’s not going to scale beyond a few thousand users. How will you do migrations? 

Surely you could also avoid using git and just setup append only tables in your db? Why do you need the extra steps?

1

u/plxs05092026 Oct 16 '26

Fair, git is the part I'm least sure about, and append-only tables would do the same job with fewer moving parts. On migrations: the log is never rewritten, each line type is versioned and new code reads old lines, and the index is rebuilt from the log when its version changes. That per-user rebuild is what I haven't measured at thousands.

1

u/Express_Scene4019 Oct 16 '26

But the log is just in git right? Nothing is actually stopping it being overwritten apart from your application.

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/plxs05092026 Oct 16 '26

Not today, each user only sees their own data. If sharing comes later, it would probably go through an explicit API between homes, not queries across databases. And since every home runs the same code version, version skew shouldn't be the blocker.

1

u/evvvvr Oct 16 '26

Let me guess. The service is still shared.

1

u/plxs05092026 Oct 16 '26

Partly. Everything that touches a user's data runs as its own process, under that user's OS account. What's shared is signup, an operator panel that only sees counts, the process that mints provider tokens, and for now the machine itself. The token one is the sensitive shared piece.

1

u/bohlenlabs Oct 16 '26

You mean something similar to https://turso.tech ?

1

u/plxs05092026 Oct 16 '26

Same idea, one SQLite per user. The difference is that here SQLite is only a rebuildable index, and the source of truth is each user's append-only log, all self-hosted. Turso is a good reference for how far the pattern scales, though.

1

u/coldflame563 Oct 16 '26

RLS in Postgres would solve issues easily.

1

u/plxs05092026 Oct 16 '26

It might. What I'm wary of is it failing open, like a new table shipped without a policy. Do you check for that somehow?

1

u/coldflame563 Oct 16 '26

Do everything via migrations of some sort ie alembic. Write a unit test that ensures all migrations have whatever.

1

u/plxs05092026 Oct 16 '26

Good guard. A CI test that checks the catalog for any table without RLS enabled and forced would close most of it. Thanks.

1

u/coldflame563 Oct 16 '26

Yup. Happy to help. Also, I'm not sure what language you're building in, but check out the archunit family of tests/test-suites. Helps enforce good coding paradigms.

1

u/plxs05092026 Oct 16 '26

Python here. import-linter looks like the closest thing, I'll check it out. Thanks again.

1

u/coldflame563 Oct 16 '26

Definitely not. First of all, you should use the astral suite, ruff, ty, uv to cover your main bases. Secondly, https://github.com/LukasNiessen/ArchUnitPython

1

u/plxs05092026 Oct 16 '26

already on ruff, with mypy strict for types. haven't tried ty yet. will look at ArchUnitPython, thanks

1

u/coldflame563 Oct 16 '26

Addendum: I do this with routes to make sure I got all of them with auth. Similar idea. the AST is your friend!

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/plxs05092026 Oct 16 '26

The handshake story made me laugh, and noted. Support time is a good point. Did they end up building internal tooling for it, or were people connecting by hand until the end?

1

u/grahambinns Oct 16 '26

Up until the point where I moved on from that contract, support were still using Metabase (a whole separate level of awful) to connect manually to customer databases. As a result, there were certain flows through the software that would cause the support team a real headache to investigate.

The last thing that I was building before the contract ended was the foundations for an event driven architecture. As part of that, I deliberately built tools for the support team to be able to look through the event stream without having to muck around connecting to individual customer databases.

The plan was – as far as I’m aware it is – to migrate to that EDA and then eventually to re-platform everything in a multi tenant DB architecture

1

u/Horror-Water5502 Oct 16 '26

Who need databases when you can have .jsonl.zst

1

u/plxs05092026 Oct 16 '26

Funny you say that, the source of truth here is literally JSONL. SQLite is only there so search doesn't mean grepping it.

1

u/Horror-Water5502 Oct 16 '26

I don’t know how big your data is, but if it’s append-only, I’d tend to compress it periodically. It doesn’t cost much and it can save a lot of space on JSON. If you want to run a grep, you just need to decompress it and pipe it into

1

u/plxs05092026 Oct 16 '26

Good tip. The logs sit in git, which already compresses them under the hood.

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/plxs05092026 Oct 16 '26

It's actually close to that already, each user's home is basically a local-first app that happens to run on a server. The part i'd skip is users choosing when to update, someone above had a rough time with that. The inbox idea for cross-user stuff is nice though.

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.

1

u/plxs05092026 Oct 16 '26

Fair split. The bet here is that per-user overhead stays small since there's no db server per user, but i get the point for lots of tiny accounts

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...

11

u/TheDuckRaisedALion Oct 16 '26

Nooo, you never want to rely on tests OR memory for security. You want something built into the database or data access layer that every query will go through and will fail if there isn't a valid user and tenant attached.

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. Might be easier to make each SqlLite DB single threaded. How will you handle race conditions and data consistency if multi threaded ops are allowed?
  2. You should probably define a max size per DB. SqlLite being an in process DB means operations will start getting slower as the size grows.
  3. You should have a plan for sharding within a user in case their data size grows beyond size allowed in (2) above
  4. Instead of storing the indexes in git, why not store in blob? Blob is perfect for this and will save you unnecessarily long CI times

2

u/rrrx3 Oct 16 '26

At Cloudflare scale, yes. Willing to bet on the scale OP's operating at? This is a disastrous architectural decision for most people and companies.

From a software architecture perspective, sure, you CAN do this. From a business and human (or even agentic) operational perspective, this is one of the dumbest things I can think of. This is cart-before-horse shit. Do your customers even need this? I ran product for an Enterprise B2B SaaS for 2 years and outside of 2 customers who were Tier 1 Global Investment Banks, we never needed isolated tenants. We started out with isolated single-tenant deployments, and migrating to multi-tenancy with bespoke deploys for those client exceptions saved us millions of dollars a year in infra and support spend.

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/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. blah
  2. 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.

1

u/combinesd Oct 16 '26

That being said Im realizing I'm not so sure that my clients care as much as I thought and will likely convert to shared and then simply allow them to branch off if they want to be independent.

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?

1

u/plxs05092026 Oct 16 '26

Thanks. Per-tenant versions I'd actually avoid, after what someone here said about regulated clients dragging out upgrades. Moving tenants between servers is a real plus, though. I'd rather not get into the business side, but your point stands: outgrowing this would be a good problem to have.

0

u/[deleted] Oct 16 '26

[deleted] — view deleted comment

-14

u/plxs05092026 Oct 16 '26

Possibly. Which part do you think turns into hell first? That's the bit I'd actually want to plan for.

12

u/_itshabib Oct 16 '26

Eventually this things need to be deployed somewhere and managed.. ur gonna make ur infra/sre team manage databases that can grow with users? It can be hard to even manage one let alone a ton of em. Database developers expect multi tenancy and high usage. It's what they are built for. It's much easier to make a code fix to fix something than potentially a database.. what's the backup policy going to be like. How do you manage access controls for each one individually. How does all your code clients reason about which to hit for which users. It sounds extremely wasteful too. When u have database technologies that can handle hundreds of thousands of ops a second and TBs of data there is just no reason to try and do this.

-2

u/plxs05092026 Oct 16 '26

Fair list, but some of it lands differently here because there's no database server per user. Each user's queryable state is a SQLite file next to their log, so there's nothing to tune or patch per user. Routing is the request landing on that user's own process, access control is that process running as its own OS user, and backups are one job run per home. Where you're right is the first time something has to be fixed across every home at once. That's the real test.

9

u/_itshabib Oct 16 '26

My opinion is that there's not much novelty to really figure too much with some of these things nowadays. We all kinda know just what makes sustainable software and how. Clever yes, will it work for a bit, probably yes. But....ton changes when u start to become a real company. I would just be mindful of that.

-2

u/plxs05092026 Oct 16 '26

Fair, and noted. Boring usually wins for a reason. Thanks for taking the time.

1

u/_itshabib Oct 16 '26

Sure ofc. In my exp for what it's worth with these things is that they usually are motivated by trying to solve a specific problem. But when u really decompose that problem to it's underlying principles and needs there are usually a lot of different things that come up that when put together feels more natural and simple. When u go small to the size of a fairly large org things become more of people problems than software. U do not want to also have a complicated piece of software because it just makes the people problems, support, SLAs, much harder to reason about and manage.