MongoDB for Developers with Python Transcripts
Chapter: Modeling and document design
Lecture: Do you have an integration database?
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
In order to answer this question about whether you have an integration database or an application database, let's do a quick compare and contrast,
0:08
especially in large enterprises, you'll see that they use databases almost as a means of inter-application communication,
0:16
so maybe you have this huge relational database that lives in the center with many, many constraints, many, many store procedures,
0:22
lots and lots of structures and rules, and so on, why— well, because we have a bunch of different applications and they all need to access this data,
0:31
maybe the one in the top left here it needs users but so does the one on the right, and their idea of users is slightly different
0:37
so this user is not like a real simple thing, it's really quite complex it's kind of the thing that will solve the user problem for all of these apps
0:44
and so on and so on, through the constraints and the way you use it. This is a decent, well, it's typically a good role for relational databases,
0:52
you're better off with other architectural patterns anyway, but relational databases are a good guarding against this kind of use case,
0:59
they have a fixed schema, they have lots of constraints and relationships and they are very good at enforcing and kicking it back to the app
1:07
and go no, you got it wrong, you messed up the data. So they can be like this strong rock in the middle.
1:12
The problem with rocks is they're not very adaptable, they can't be massaged into new and interesting things;
1:19
a rock is a rock, and it's extremely hard to change. So that's partly why some of these major enterprises
1:26
will have like weekends where they deploy a new version of an app, like we're going to take it down and everybody's going to come in
1:31
and we're going to release it; that is not a super place to be, it's also not a great use case
1:37
for document databases with their flexibility in schema design, their less enforcement at the database level and more enforcement inside the app,
1:46
because how is the app on the left going to help enforce things for the app on the right, that's not great.
1:50
So, this is an integration database, and it's generally not a good use case for document databases, if you're still using that
1:57
this sort of style of document databases, it means your queries will be more varied and you probably need to model in a more relational style,
2:04
less embedded style, just as a rule of thumb. So what's the opposite? Well, it might look like this, we have all of our little apps again,
2:12
and instead of them all sharing a single massive database you can maybe think of this is more like a micro service type of architecture;
2:18
each one of them is going to have their own database and they're going to talk to it, and then when they need to exchange information
2:23
we'll do that through some sort of web api, so they will exchange it through some kind of service broker way
2:30
they like negotiate and locate the other services, right, maybe the one in the left is about orders, the one on the right is about users and accounts.
2:38
So what that means though is each one of these little apps is much simpler, it can have its own database with its own focused query patterns,
2:46
which is more focused, easier to understand, and the application can enforce the structure and the integrity at its api level,
2:54
so this is a much better use case when you're sharing data with a document database. And in fact, this sort of whole pattern here means
3:02
we don't have to make it NoSQL versus SQL choice, maybe three out of these six are using MongoDB,
3:08
one is using a graph database and two are using MySQL, it's up to the individual application to decide what the best way
3:14
and model basically with the best database and its underlying model is. So when we have an application database like this
3:21
you are more likely to have slightly more embedded objects because the query patterns are going to be simpler and more focused and more constraint.