-1

enter image description here

The central database(blue) will hold all customer data of the project.

The local databases(green) will be deployed at the physical locations containing a copy of the customer databases. Multiple stores can be deployed across geographical areas (A, B,...N) to allow customers to register and make purchases.

When a customer is registered at a local store, it should be updated in the central database with the purchase history. When a customer is registered, his purchase history should also be available in other stores.

For example, in the morning, a customer can purchase from store A, and afterward, customers should be able to purchase from store B/C or any other without registering again.

MySQL will be used as the database.

Advise is expected,

  1. Is there a database architecture or pattern that we can achieve this?
  2. What's the best approach to implement this?

Referred: Database Architecture, Central and/vs Localized Server

Techie
  • 44,706
  • 42
  • 157
  • 243

2 Answers2

1

There are three popular replication algorithms according:

  • single-leader. When just there is one leader node
  • multi-leader. When there are many leader nodes
  • leadeless. When there is no leader node

Read more about these algorithms in "Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems" by Martin Kleppmann. As a quick overview, you can read this article "Database replication — an overview".

When a customer is registered at a local store, it should be updated in the central database with the purchase history. When a customer is registered, his purchase history should also be available in other stores.

It looks like you need to use master-master replication or multi-master or multi-leader replication. As wiki says:

Multi-master replication is a method of database replication which allows data to be stored by a group of computers, and updated by any member of the group. All members are responsive to client data queries. The multi-master replication system is responsible for propagating the data modifications made by each member to the rest of the group and resolving any conflicts that might arise between concurrent changes made by different members.

And MySql supports this:

MySQL Group Replication is a MySQL Server plugin that enables you to create elastic, highly-available, fault-tolerant replication topologies.

Groups can operate in a single-primary mode with automatic primary election, where only one server accepts updates at a time. Alternatively, for more advanced users, groups can be deployed in multi-primary mode, where all servers can accept updates, even if they are issued concurrently

I highly recommend you to read chapter "Replication" of book "Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems" by Martin Kleppmann

StepUp
  • 36,391
  • 15
  • 88
  • 148
  • Multi-Primary works only in a ring, not showflake. I suggest that it is impractical not only because of the topology but also because of its reliability -- any node failure leaves the setup in a mess. – Rick James Nov 03 '22 at 17:47
  • I don't think Group Replication does what the OP wants, either. And Galera does not scale well beyond 5 nodes. – Rick James Nov 03 '22 at 18:26
  • @RickJames *I suggest that it is impractical not only because of the topology but also because of its reliability* I do not have practical knowledge, but this page says that [Tungsten Replicator allows for global transaction IDs, advanced topology support such as active/active, star, and fan-in, and enhanced latency identification](https://www.continuent.com/products/tungsten-replicator) – StepUp Nov 03 '22 at 19:56
  • @RickJames It looks like group can have more than 5 nodes. [A group can consist of maximum 9 servers. Attempting to add another server to a group with 9 members causes the request to join to be refused. This limit has been identified from testing and benchmarking as a safe boundary where the group performs reliably on a stable local area network.](https://dev.mysql.com/doc/refman/5.7/en/group-replication-frequently-asked-questions.html) – StepUp Nov 03 '22 at 19:59
  • @RickJames *I don't think Group Replication does what the OP wants, either.* Maybe I misunderstood, but OP said *it should be updated in the central database with the purchase history. When a customer is registered, his purchase history should also be available in other stores* – StepUp Nov 03 '22 at 20:02
  • Tungsten is, if I am not mistaken, a costly add-on. – Rick James Nov 03 '22 at 21:30
  • You and I are sharing the history of this discussion, but there is only one database involved. There are no local copies scattered everywhere. – Rick James Nov 03 '22 at 21:33
0

Short Answer: Nothing standard within MySQL.

Long Answer: It is a tough problem because of network outages, temporary server outages, etc.

Partial solutions:

The "right" answer is to have every "customer" not have its own database, but instead, do all reads and writes on the "Main computer".

To have only local data on each "customer" db (which would be a Primary), the Main could be a Replica receiving updates from each customer. But this says that the only complete copy is on Main.

To have each customer have all the data, you must write to main (Primary) and read locally (Replica).

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • If I understood correctly, single-leader replication algorithm is advised. However, it looks like it does not comply with requirement to have *multiple stores can be deployed across geographical areas (A, B,...N) to allow customers to register and make purchases*. – StepUp Nov 03 '22 at 20:08
  • Just as there's only a single instance of StackOverflow -- you do not have your own "local" copy of SO. – Rick James Nov 03 '22 at 21:29