-2

I am not asking what are advantages of two databases - the first for reads and the second for writes. I am asking WHEN I should have two databases for reads and writes? Probably there is no simple rules but when I should consider it? What is a rule of thumb?

  1. What if I have much more reads than writes? Is it a good reason for having two databases?
  2. What if I have the same amount of reads than writes? Is it a good reason for having only one database?
3
  • 8
    The rule of thumb is: don't use two databases unless absolutely necessary. State synchronization is just a huge pain in the a**.
    – freakish
    Commented Jun 10 at 5:33
  • So when is it necessary? Commented Jun 10 at 8:41
  • 1
    When you have 30k reads per second, i.e. when you are Twitter/X. And even then only after careful consideration and tests.
    – freakish
    Commented Jun 10 at 8:46

2 Answers 2

2

Unless the data you're reading is completely disjoint from the data you're writing, you don't have two databases, you have one database that's in two pieces.

If you have more reads than writes AND your single DB is heavily CPU loaded, or network IO loaded, then adding a shard should improve its performance.

1
  • Why would a shard alleviate network load? Read side still has to receive all updates over the network and and client traffic is not reduced.
    – Basilevs
    Commented Jun 10 at 9:42
2

CQRS helps when your inserts and/or updates are expensive or lock tables and rare compared to reads. AND when you are ok with stale data for some reads.*

So you should think about using it when you are in that situation.

There's no "When" in the sense of, my DB can handle it for now let not think about it. You need to make scalable solutions and you can see your solution won't be able to scale, so you add a solution or start designing a cool "fail whale" logo

`* There are a bunch of other use cases and I have glossed over a lot of stuff here. But you get the general idea.

1
  • @aleksander you say you are not askign abot the benefits of CQRS, so i didnt go into it. but i kinda think you are?
    – Ewan
    Commented Jun 10 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.