Introduction the Components to implement a better system architecture
Hello fellas, this is the first article I have written, I want to try to share my opinion from my point of view, hopefully this article can add insight to us.
Before going into the discussion I want to explain the purpose of this article, we know that every application has an architecture called the system architecture. The system that we will discuss is more of a system with a microservice architecture, i will explain what the components are to make the system architecture and its functions. Here we go.
- Load Balancer
The Load Balancer is the first one we will cover. Maybe you have heard of the term load balancer. Yes, a load balancer works like a load balancer. Its function is to divert traffic from one server to another similar server. The purpose of this load balancer is usually to scale up. Usually the scale up is divided into two, the first is vertical scale up, namely by increasing server specifications. And the second is horizontal scale up by increasing the number of servers. If our application has more than 1 server, friends must use a load balancer in addition to dividing traffic so that it is balanced, if one day one server dies, the load balancer will only direct the user to a server that is still running. Therefore the load balancer is important to improve optimization as well.
- Database Replication
Second, we will discuss databases. Why does the database need to be replicated? what is the purpose of replicating a database? At first glance there may be many questions in the minds of friends for what this database replication is. The purpose of this database replication is still the same as the goal of our previous topic, which is related to scale up. Database replication is included in the horizontal scale up. Why ? because we increase the number of databases to improve application performance. With the existence of several databases, we can distinguish the database to insert and the database to read data. Why should it be distinguished? because fundamentally when the database inserts and reads simultaneously it makes the database work twice and becomes heavy. Apart from that the purpose of database replication is to back up data. Imagine if one day the datacenter, which is the physical server that stores our database, is hit by a disaster, we still have a backup of the data in another database.
- Cache
The third is cache. Cache is temporary storage. The purpose of the cache is usually to store data when the application or server is first accessed so that subsequent data requests can be obtained faster. The cache we are discussing today is more of a backend cache. If the frontend we can cache through the browser. What about the backend? The backend can also store cache by storing it in memory. Our question now, why do we have to store it in memory? Because when we access data from a database, it means we access it from a disk. We know that the speed of reading memory is much faster than having to read repeatedly to disk. However, we must still carry out the right strategy in managing our cached data so that there are no conflicts or data differences between the data in the cache and in the database.
- CDN
When I write a CDN, what do you guys think? CDN or better known as content delivery network is to make copies of the data that is distributed to each node or different point in the geographical zone. Usually the data that uses CDN is public data on the web or application such as application logos, styles and then images. The purpose of CDN is also to reduce latency when accessing data. For example, suppose the application that we make is run on a server whose datacenter is in Jakarta. Then there are other users from other countries accessing our application, there will be a difference in access speed between users in Indonesia and users in America, we can just create a new server in America, but imagine if there are other users who access too, maybe we need a lot of servers in another country? the answer is no, we can use a CDN for content only because it can save even more in terms of costs.
- Message Queue
When we shop at a mall or supermarket, we definitely queue up when we want to make a payment. Yups, it’s also the same on the system. When creating a highly scalable system we have to prepare a message queue. Message queue does not mean only messages are queuing, we can do any process, but because it works like messages, it is called a message queue. So how does the message queue work? Well, let’s say that in an application that we make, there is a process that is heavy and quite time-consuming, for example, exporting data. When there are only a few users exporting data it will feel light, but when there are tens or even hundreds of users exporting data at the same time. What will happen ? The server will not be able to carry out the process, therefore a message queue is needed. This message queue works like a message where the message queue will publish then there will be workers who subscribe. When there is a queue in the message queue, the worker takes the message data one by one and starts executing according to the commands in the message. So even if there are thousands of queues, it will still be done by the server properly because it will be executed one by one.
- Logging & metrics
When the application is successfully run on the production server, is our job as a system designer done? Of course not, even after the application is successfully deployed we need to perform maintenance again. Applications that we design sometimes still have bugs and can make the application stop running suddenly. Therefore we must be confused why the application stops? we also definitely need to find out the cause is not it. Therefore we have to create a system log on our application. The goal is that when the application stops we can trace what causes our application to crash, with logging we can save more time when doing maintenance.
- Automation
last but not least, namely automation. Where should we put automation? In all parts. At the time of application development at the beginning we have to implement TDD. What is TDD? TDD is Test Drive Development. We develop the application while also designing the automation testing. Why do we need to need automation testing during development. This does require a lot of effort, but when our application gets bigger, it actually makes it easier for us to handle bugs. Because at the time of development we don’t know if there is code that changes other features to be inappropriate. Therefore, with automation testing, we can test with just one click. Then we have to implement automation during deploy and development, this is usually known as CI/CD. What is CI/CD? CI/CD is continuous integration & continuous delivery. We discuss CI, usually with CI we make our application easy to integrate from development to staging or from staging to production without requiring a lot of effort, usually at this stage it is also coupled with automation testing. Then the CD is automation which makes it easier for us to deliver our code, making it easier for us to deploy automatically even if we update our application.
Those are some components that we can learn to make a better architecture from my point of view, if there are additions or something that is less precise than what I said, please provide feedback. Happy Code Everyone !