Scaling Web Apps & Database in the Cloud
Reduced. Cache provide, a solution for data persistence, while. Memcache. It doesn't. When. Users search for a certain information in our website a request, will hit the server in order to search. For that information from, the database. Most. Requests, are similar, and therefore. So. Why, not here, caching. Those, requests. With, their response. Data. Well. Here. Were elastic, search terms to play. Elastic. Search can. Cache boost, requests, along with their. Response. Data. With. This way we, don't, need to access the database in order to retrieve that request. Or that data related, to the query, but. We, can retrieve it from a caching system which. Is, faster. Than, accessing, the, database. Elastic. Search can, also provide, a near real-time search. As you type Sinister's, this. Reduces, the load on the database which itself, reduces the, load on the server as the request will be processed in, less time. Elastic. Search is accessible, via REST, API and, requires, changing, the App Store's code to use it, elastic. Search could also be used for log analytics, and real time application. Monitoring. Another. Good practice for scaling, web applications, is to split, the monolithic, application. In two parts the, first one is the front end application. And the, second one is the. Back end application, that, contains the web services. With. This splitting, we, can host each part, on a separate. Server. This. Will reduce. The amount of loot, on each server which. Will help us to scale, the. Application. When. I convenient, for this approach, is that we need to change. The, source code of the application because, here, we are splitting by. Two, parts, to live and to different, servers. We. Did split the monolithic. Application, in two front, end and a back end but, we are still getting a growing number of requests. From our users, and most. Of those requests. Are hitting, the. Back, end side. So, the back end is struggling to, to. Scale so. What if here we can split. This, back-end into. Multiple, parts. Well. Here, we're microservices, comes to play. If. We analyze the back, end we can see, that it is composite. Of multiple, modules. We. Can find modules, for authentication. Modules. For payment, for, recommendations. And many, more. So. The philosophy of micro-services, is to say why not why, we. Still get, all those modules into one, application, hosted into one server. Why. Not splitting. This. Monolithic, up, so. That we can have multiple. Micro. Applications. Connected. It to each other and, each. Micro. Application, or Mac micro, service, will, be hosted, on a different, server, those. Servers we call them the, containers. With. This way we, can not, only reduce, the. Load on the. Ethic application, but we could also scale, each part. Or each. Microservice. Differently. Or, independently. From the other micro-services, maybe we are having. The macro service responsible. For payment is more. Used than the, micro service responsible. For, Identity, Management so. In this way we can have two, containers. To. Handle, the payment, modules, and only, one container to, get. The requests, for the authentication. But. Be careful here that going. From monolithic, to micro services requires, lots, of change in the application source, code it's not unusual to be required to rewrite the entire application.
From Scratch. Microsoft. Azure supports. Docker, containers, and also, container, orchestrators. Like kubernetes, service. Fabric and swirl with. Micro services, and the monolithic, application. Is split into small. Pieces based, on business domains. Can. We go deeper more than that to split the application, to smaller pieces. Well. Serve enlist apps makes, it possible. Self. Silvered list apps is a small piece, of the, application, on its own instance. This, instance, is managed, for you so you don't need to take care of any container, or VM, it. Can scale out automatically. Depending. On the loot typically. You can use it for resizing or processing, images, starting, a new job on a database, etc. Anything. That is more often and dependent, from the business, logic. Now. That we have multiple tiers, running, each one, on a different IP, address, the, client application will, ask where. Do I need to go well. Here, where API, management, also call it API, gateway, comes. To play. With. Traffic manager we can distribute, the load between different, virtual, machines and, here. With API, management we can distribute the load between different, micro. Services or API, endpoints. API. Management can't take into account the load on each micro service our. Micro, services need to communicate with each other so they can use rest, Web Services for communication. But. Some of this communication doesn't, need to be run it synchronously. So, why, still. Waiting, for a, response from, the, server. When. Here. Pew's comes, to play. Queues. Are a good, solution for asynchronous. Operations. Because. With restful services we, need the. Server, to, be available, and also, we need to wait for the, server to complete. Processing. The, request. With. Queues now, we, don't need the. Server, to be available. To process the request but. We can stand our request, to a, queue and that request will wait until the. Server, will be available. Later to, handle it so. We are not will block it while, waiting for the response from the server this. Approach, helped, to decouple the different parts of the software and makes, them easily scalable and resilient. There. Are some other good practices, for scaling, web applications, that doesn't, require using, cloud services.
From. Those practices, is pushing. Tasks, to the client-side. For. Simple tasks like resizing, images. The. Client can. Do, this, processing. Of the image so why. Bothering, the, server, with. Some. Of. Those simple, tasks. Another. Good solution, to not bother the server is to not send the same HTTP. Request if we, are sure we'll, be getting, the same response. Well. Here. Caching. The HTTP. Requests, until the browser is, a good practice. The. Browser is intelligent. Enough to. To. Cache those. Requests. With their responses. And also to add, a, TTL. Time-to-live, for, each object stored, in its cache, so. That we can say that, the. Objects. Are saved and the cache only, for three days for example more if we go, beyond, three days then that information will, be either updated. Or deleted. Until. Now we have explained, the different options for scaling, a web application but. Most web applications, connects to a database so. When we have a growing number of requests. Those, requests, will also hit the database, like. Web Apps the database cannot receive, an infinite amount of queries, not, only that but also the database can, have or have. A maximum. Amount of data that it, can store, hence. It need to be scaled. So. For the next. Parts. Of this video we'll be discussing the different options, for scaling, the database. The. Simplest option to enhance the database response, type is to, use a built-in feature that. Is built to. Do exactly. That. Well. Here I'm talking about caching. Data, sequel. Databases, have, a built-in, feature called. Buffer. Cache. Which. Help to cache, the most frequent. Queries. Caching. Queries, is limited, by the size of the available, memory. But. When we have a big. Number of queries that does. Need to go, fetch data from our tables. Than, here we need a better, solution, to retrieve, data, from our, big, tables. Well. Here and Xing could help and. Xing. Will, help, us to not, loop the, entire, table when, looking for a certain, information, from a row. Even. With using indexes, we might be below the, required response, type. This. Might be because of using. Non-optimized, sequel. Queries. So, we need to analyze our, web, application. And all, the. Sequel. Queries and that. Are inside, our web, app. With. The quick analyze of the source code we find that we are we. Might be using an ORM object, relational, mapping, which. Will generate, the sequel, queries, and in. Addition to that it, will try, to. For each request we will try to open the, connection to the database then, it closes the connection which are two, additional.
Steps. That takes, more time, so. What if instead of using an ORM, was, if we can use for, storage procedures, which. Takes less, time to. Query. The data from the database. At. The end we can mix. Stored. Procedures, and ORM. Unto. The same application so we have the, simplest queries. Use. This ORM. And. The. Most sophisticated queries. That takes time we can optimize those, using, the storage. Procedures, if. The limits of a one, single database are wretched then, why not creating, multiple instances. The. Duplication, can. Be based on multiple, criteria well. Let's start by the one base it on read, or read write operations. Sequel. Queries are either reading, or writing data. From. Here engineers, ask it why. Not to write to. A database and read from another one. This. Way they can reduce. The load to. A health, by, balancing, it on two, databases instead, of only one, the. Readwrite database, will take the responsibility to. Update, the read database. So. That they, have almost the same exact, data with. The web application, when we wanted to go further more, than duplicating, instances. We, split the application, and two small components, we call it the micro services. Come. The same logic but be applied to database. Another. Criterion, for replicating, database, is based on splitting the table, itself this. Is called partitioning. Or sharding. Well. Let's start by partitioning. Partitioning. Is also, called, split, vertically. Partitioning. Divides. A table, into multiple, tables with, fewer, columns. The. Customer, table that have 20 columns will be split into two or more tables the. First table will have columns, from, 1 to 7 and the second one will have the, columnists from 8, to 20 of. Course. Each table, contains, the primary key to join data from, both tables, this. Is useful when usually, only. The, first, seven, columns, are needed. So. It takes less, time to, run. As it. Will bring less, data those. Two tables could, be on the same database. Or in two separate. Ones. Sequel. Databases report, this case by providing, features, to, recognize, from. Which, partition, to get the data. But. Be careful here that vertical. Partitioning. Should be considered, carefully because. Analyzing. Data from multiple partitions. Requires. Queries. That join the tables, that is. The case where, we need all the 20, columns, we. Split a table, vertically, by splitting the columns, can. We split it based on the roads well. That is college sharding, or split. Horizontally. Charting. Provides. Or divides, a table, into, multiple, tables each table, then, contains, the same number of columns but, fewer rows, for. Example, the customers table can be partitioning. To five smaller, tables, each, representing. The, continent, for. A group of customers. Knowing. The customer location, will help to read redirect. Query, - right to. The right partition, - process, less rows, the. Smaller tables, can. Live in the same sequel, instance, or in, separate ones the. Same as with partitioning. Horizontal. And vertical, partitioning, can be mixed it together, but. We weren't adhere that, tables. Should be partitioning. A partition. It so, that queries, reference, as few, tables, as possible, otherwise. Excessive. Unions, queries. Use. It to merge the tables logically, at query. Time can, affect, performance until. Now, we have seen splitting, tables, based on their columns, or rows but. Can we split tables, and to group of tables, well, that, let's see dee. Dee dee dee dee. Dee also called domain driven design. So. We have split the web up and to smaller micro services, based on the context, or domain the. Same thing could be applied, to the. Database, using, DDD. So. That each domain has its. Own set of tables. Tables. For payment, for another. Set, of tables, for commands, and so on. Imagine. Now that each, micro, service have its, own domain, tables. Living, in the same container. But. We wanted here that the objective, of DDD is not to scale the database but that is a consequence. Of its application. And if. It's not built, from, the design phase of the project it will require a huge, amount. Of change, to, the source code of our app still. The sequel databases are not enough for handling all the loot well why not writing no sequel. Sequel. Databases are based, on schema, and relationships, between tables. This. Is at the heart of its, limit, to reach infinite, scalability, on. The. Other side no. Sequel databases save data, as key value pairs so, no need for schema. Neither, for. Terrible relationships.
For. That reason tables. Can be split, horizontally and. Intently. But. We warn adhere that no sequel eliminates. Relationships. Between tables so. You still, can do tweaks, to establish, relationships, but. That, is not recommended, so, you have better to make the. Decision. If it is still suits, your need or not at. The end scaling, an application, on the cloud is not only the responsibility of, the architect, but it also requires the developers, to think about, the. Stateless, aspect, and DBA. To think, about, partitioning. The database. This. Work should be done at first one. Important, note to think about, is. Also, metrics, and analytics because, those, who. Can tell if we, need to scale up or down, and, especially. What. Exactly, needs to be scaled. So. I hope the video was helpful for you and thank. You.