I'm looking at migrating my web-application from an SQL database to a key-value store, so I can scale my app horizontally.
I'm planning out how to migrate my schema - and I'm sure there must be a pattern for doing this.
I'll give a Mickey Mouse logical example to show my thinking. Here is a simple library system in a relational database with Book
s, Person
s and BorrowEvent
s. You can join from the Book
s to the Person
s using the BorrowEvent
to see who has borrowed which Book
.
Book
- BookID
- BookTitle
Person
- PersonID
- PersonName
BorrowEvent
- BorrowEventID
- BookID
- PersonID
Now let's try the following refactor:
[Key][Value]
- ID/BookName
- ID/PersonName
- ID/[String]"BorrowEvent-"+[ID of BookName]+"-"+[ID of PersonName]
This works by querying on the BorrowEvent, splitting the String of the value using a regex to get the IDs.
Now this has several limitations. If I want to have add an Author
to my Book
, I've got to add an additional hop to retrieve my book information. Same goes if I want the Person
to have a first and last name.
I imagine there must be a pattern for this transformation from relational to key-value store. (Or multiple patterns). I just don't know what the name is.
My question is: What pattern should I use for refactoring my relational SQL database to a key-value store?
Assumptions:
This post lists a number of techniques, including:
Nested Documents Flattening
i. Numbered Field Names
ii. Proximity Queries
Batch Graph Processing