Hi, everyone, and welcome back.
Now, in today's video, we are going to discuss about ideas, read replicas.
Now, before we discuss about the read replicas in databases, let's discuss a simple use case of a
bank which will allow us to understand the overall concept in much more easier way.
Now, let's say that in a bank for different kind of work, there are different types of people that
you have to approach.
For example, there will be a different cash collection guy.
There'll be a different person who might be collecting cheque for inquiry, there might be a different
person maybe to open a bank account, there might be a different person and so on.
So overall the work is distributed among multiple people in bank and this allows the oral operations
to work efficiently.
Now when we discuss about database, if you are making use of a single database, you're for performing
all the kind of activity it can be read operation, it can be right operation, etc. In such cases,
the overall load on the database will increase and this will slow down the operations.
This can also be seen in the diagram where you have multiple clients, you have multiple servers, and
all of them are connecting to the single database here.
So in order to overcome this, there is a concept of read replica that has been introduced in database
at a high level overview read replica allows the customers to offload the read request or analytics
traffic from the primary instance.
Now, this can be understood with this small animation where you have a single database also referred
to as a primary database.
Now in a read replica base scenario, there is one more database that has been set up, and between
both of these databases there is a replication that is configured.
So this means that any data that is written in the primary database will also be copied to the read
replica that is running.
All right, so you have a primary DB and you have the read replica.
Now generally what happens in this setup is that all the right related operations goes to the primary
database and all the read related operations goes to the read replica.
Now, since there is a replication that is ongoing between both of these database instances, read operation
when run on the replica, it will not really have an impact because the data ultimately remains to be
the same.
And in such kind of a setup, the oral load is distributed.
So this is the concept of read replica.
Now in a similar way, if you're making use of ideas, Amazon provides easy way to go ahead and implement
the read replica.
So as we're discussing, the oral functionality remains to be the same.
It's just that if you're using us, you can go ahead and create read Replica within 2 minutes.
Now, before we proceed further, let's go ahead and quickly look into it from a demo perspective so
that our basic understanding of read replica is clear.
Now currently I'm in the IDS console.
I have one database instance that is running and the name is JP Labs DB.
Now, if I quickly open this up, let's go back down here.
You see that in the replication, you have the primary instance here, the role you see it is primary
and you also have a replica over here which is running in the Mumbai region.
So let's quickly open up the replica.
Now, here, one thing that you will see is that the endpoint is different between a primary and a replica.
For example, the end point for primary escape will be followed by the Amazon place and you have the
read replica followed by Amazon.
So based on the application, you can configure whether the application should perform the operation
on the primary DB or the read replica.
For an example, let's say that you have an analytic application which only performs read request.
So instead of giving the URL of the primary DB to that analytic application, instead you give the URL
of the read replica and the load will be distributed here.
Now, in order to test if the replication between a primary and the read replica is working as expected
in ideas, let's go ahead and connect to both of them and perform some interesting practical.
So let me quickly go to the AC two instance here.
I have one instance running.
Let me quickly connect to the instance through the browser itself.
Let me quickly switch to the root user.
And first, let's go ahead and connect to the primary DB, or I'll copy the endpoint URL.
I'll clear the screen.
Let's quickly connect here.
I'll specify the username and password on it.
I'm connected here.
Now, if I quickly do a show databases here, there are certain databases that are available.
Now let's quickly create a new database.
I'll say create database testing.
Oops.
We made a small typo.
It should be database instead of databases.
All right.
Now, if I quickly do a show database here, you see that we have the testing database that is available.
Now, let me do a control D so that we can log out.
Now, instead of connecting to the primary db, this time we will be connecting to the read replica.
So let's copy the endpoint of the read replica from the instance.
Let's go ahead and try once again.
I'll say user name of admin and I'll specify the password.
And we are connected now in the replica.
If I do a show databases at this stage you see, you can see the testing database.
Similarly, one important thing to note is that since this is a read replica, let me quickly show you,
since this is a read replica, it is primarily meant for read operation.
You will not be able to perform right operation on the read replica.
So let's also go ahead and try it out.
So let's go ahead and try to create a database.
I'll say a replica DB.
And immediately you see you got an error stating that my SQL server is running with the read only option,
so it cannot execute this statement.
All right.
So I hope with this you understood the basics of what read Replica allows us to do.
Now, before we conclude few important pointers that needs to be noted.
First one is that you can create one or more replicas of a given source db instance and serve the high
volume application.
Read traffic for example, you have a primary database and based on this primary database, you can
go ahead and create multiple set of replica.
You have read replica one, read replica two and so on.
So let's say sometimes in organizations you have very high amount of read traffic, but very less amount
of write traffic.
In such cases you need more set of read replicas that can serve the read only traffic.
In such cases, you can use this type of architecture.
Second important point here is that with Amazon ideas you can create read replica in a different region
from the source DB instance.
For example, here you see that the source DB is based on us is to one region and you have a read replica
in the AP south one region.
So this kind of architecture is also supported.
In fact, the architecture that we had taken here, let me quickly show you.
So the primary database here, this is based on the US region, which is US East one, but the read
replica, it is based on IP South one region, which is the Mumbai region.
You see you have a mumbai region and you have the Vergina region.
So this kind of architecture is also supported.
So that's the very high level overview about the read replicas.
And with this will conclude today's video.