Scaling Web Apps & Database in the Cloud

Scaling Web Apps & Database in the Cloud

Show Video

Hi. Developers. Scalability. Is an important, part when, architecting, a web application, cloud. Providers, like Microsoft, Azure provide. Some. Services, that help us to scale the, web application, and the database. This. Presentation. Or work you through the concepts, of scale. Up scale, out. Load. Balancers, traffic. Manager, CDN. Caching. Elastic search micro. Services and so on. For. Scaling the database, will, be discussing technologies. Like, charting. Partitioning. DDD, nor sequel, and many. More. I'm. First time delay Microsoft. MVP join. Me in this video to, learn how you can scale, your web. Application, and your database, in order to support. Thousands. Or millions. Of users. Let's. Imagine we have a business web application, hosted, on a virtual machine at first. Our. Website. Will get 10,000. Requests, per second for example but, after we have launched it a new cool product, or service everyone. Wants to use that service. And so, the number of requests. Will. Grow. Up so, the, virtual machine, will take, all that load and at, a certain, point the. Virtual machine will, stack because it has a limit about, the, requests. Or the load that it can handle. So. When it reaches its limit, the, virtual machine will start rejecting, the. Incoming. Requests. That's, a bad news, for your business, so, what we need to do here is, to. Move. To a bigger, virtual. Machine. That's. The, first option we consider and we call it scale. Up. So. A scale app is moving, from smaller. Virtual. Machine to a bigger virtual. Machine the. Big what. We mean by bigger virtual, machine is more, RAM. And more CPU. So. Here we can move from 8 gigabyte. And, 8. CPUs. Virtual, machine to a begger, vm that have let's. Say for example 500. Gigabyte. Of ram and, 64. Cpu for example. This. Is an. Easy, option to, do because it only requires. Moving. Or copying, the, application, from the smaller VM to the bigger one so it doesn't it. Doesn't involve, changing. The source code of the application, if. Our, website, is getting. More requests. Coming from our users, then, one. Single VM, may not be able to handle all this load and scale. Up in this case will reach its limits. Because. At the end one, single VM cannot have an unlimited amount of RAM, and CPU. So. What is instead, of having, one. Single via what if I can have multiple. VMs. Well. This solution is called at scale, out. So. It's Caleb, we focuses on making one single VM bigger. Scale. Out we'll, try, to create. Multiple. VMs. So. With multiple, VMs let's say nvm for. Example we'll, have an. Amount. Of CPU, and an. Amount. Of RAM, per seat per VM. Having. Multiple, VMs instead, of one VM means, that now we will have multiple. IP addresses exposed. To our, users. So. Here. If an, HTTP, request is coming from our user then. Here, it will go to VM. 1 or VM, 2 or VM, 3, well. We, need the mechanism, that, can handle. Those, requests, and can redirect the request, to the right server. This. Technology, is called load balancer, or traffic. Manager. Load. Balancer, or, ethic manager, will, get the HTTP, requests, from the users and then, it will choose to, to, redirect that, request. To. VM. One, two or three for example. The. With this they will ensure that our, application, will still always running. And we, can serve more requests. Our. Servers, might still suffer because of the growing number, of requests, with. A quick analyze of the content, of our web application, we, saw that we, do have lots of static content. Videos. Images. JavaScript. Files. HTML, and. CSS, files, to. Alter. Static, content is save it on the disk and we. Know that the. Hard disk takes, so, much time, an order to, be excessive. This. Results, into the, requests. Coming from the user takes so much a long, time in order to access those, resources. CD. Ends are located, in multiple locations called, point of reasons, peop, around. The world so. That it is possible to get one that is closer to the user location. Than your servers, are the. Second is accessing. The file. On the disk so, CDN, might use a combination of, HDD. S DD SSD. Or even, RAM, to. Cache these data, depending. On the frequency of data access frequency. The, time to leave TTL, can be applied to the cache to say it should expire, at a certain time, CDN. Caches, static, content, files but, what if all, we need is to cache some, dynamic, data this. Can be solved by using cash. When. Loads of sequel requests, to the database gives the same result then, it is better to cache this data in memory to, ensure faster. Data, access, and reduce the load on the database. The. Typical, case is, the. Top 10 products, displayed, on the home page 4 users. Because. It uses a ram memory and, not, disks it. Can save as much data as the, RAM do. Data. Is stored as key value pairs cache. Can be distributed. Across. Multiple regions. Every. Disk cache can save up to, 530. Gigabyte. Asher. Doesn't, provide a service for memcache, it. But. We, all read here that in case of an, underlying. Infrastructure. Is issues, there, can be potential. Data loss, however.

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.

2018-03-11 12:25

Show Video

Comments:

Houssem !!!! thank you againnnn !!

Crystal clear explanation with nice connections :) Awesome Houssem

thank you :) :)

Other news