DEV Community

Anh Trần Tuấn
Anh Trần Tuấn

Posted on • Originally published at tuanh.net on

The secrets that no one tells you about why your system can not scale up?

1. The story of Mike, my best friend

My friend, Mike, invested in the stock market and made a huge profit of $200,000. With that money, he decided to build a house so his family of four could have a spacious place to live. Mike's excitement was indescribable when the house was finally completed. As his best friend, I was the first person he invited to visit his new home. We had a long evening, talking about future plans, and Mike proudly told me about his newly built house.

Image

He had hired a highly skilled construction engineer to ensure that the construction was done perfectly, and I was happy for him. For the past three years, I thought everything was stable and Mike's house was bringing happiness to his family.

However, when I visited Mike again after three years, I noticed a sad look on his face. Mike told me that the house had been severely damaged. I was surprised and asked why, as it had only been three years, but Mike explained that the house was located too close to the road, causing large trucks passing by to create significant vibrations. The foundation was built insecurely, resulting in many cracks on the walls and other structures.

Mike also shared that his plan to add a few more rooms to prepare for a growing family might be difficult, as the house was no longer suitable as he had imagined. He took me on a tour of the house and showed me the numerous cracks in the corners of the walls. The house was not as perfect as I had thought; the rooms were all built adjacent to each other and shared the same main load-bearing wall, making it difficult to renovate or expand the space. The shared bathroom wall with the kitchen made it difficult to expand or change one room without affecting the others. The narrow hallway that all rooms had to use frequently became congested when there were many people moving around, making it difficult to move.

In addition, the house was not divided into functional areas such as living area, sleeping area, and lacked storage or temporary storage rooms. This made it difficult and time-consuming to find items, and made living in the house inconvenient. The lack of organization and arrangement in the house also led to things getting messy and difficult to manage when there were changes or additions.

Mike said he might have to rebuild the house again to fix these problems and create a more comfortable living space. Although it sounds like a big challenge, I believe that with determination and lessons learned from past mistakes, Mike will create a more perfect home for his family.

2. Building a system is like building a house.

2.1 Choosing a Location for Your Dream Home vs Choosing the Right Database for Your Application

Just like building a house, choosing the right database starts with understanding the system's requirements and operating environment. Mike didn't anticipate environmental factors like vibrations from container trucks, leading to severe problems. In the case of databases, misunderstanding the application's requirements (such as availability, scalability, and consistency) can result in poor performance or critical issues in the future.

Image

In Mike's story, an improper design led to significant problems. Similarly, choosing the wrong type of database can cause difficult-to-solve issues. There are various types of databases with different characteristics:

  • Relational Databases : Such as MySQL, PostgreSQL. Suitable for applications requiring high consistency and a well-defined data structure.
  • NoSQL Databases : Such as MongoDB, Cassandra. Suitable for applications needing high scalability, handling large data volumes, and flexible data structures.
  • Cloud Databases : Such as Amazon RDS, Google Cloud SQL. Offer high availability and easy scalability but can be more expensive.

Choosing a database depends on the specific application requirements, such as consistency, scalability, and performance. For applications requiring high scalability and flexibility, NoSQL databases might be a good choice. Conversely, if consistency and data structure are crucial, relational databases are the preferred option.

Mike's house encountered problems due to its inflexible design, making it difficult to renovate and expand. Similarly, databases also need to be flexible and easy to maintain to adapt to future changes.

  • Design flexibility : Consider the ability to scale and adjust the data structure without disrupting services.
  • Maintenance and updates : Ensure the database has tools to support easy maintenance, backup, and recovery.

Rebuilding a house can be costly, and in the database realm, cost is also a significant factor. Costs can arise from deployment, maintenance, and scaling. Evaluate the total cost of the database, including hidden costs like maintenance and scaling, to ensure the projected budget aligns with the project's requirements.

2.2 Develop Core Services

Image

When we think about building a complex software system, especially core services, choosing the right architecture plays a crucial role in ensuring that the system performs efficiently and can scale when needed. The story of Mike and his house is a great metaphor for understanding the importance of designing the software architecture correctly from the beginning.

Mike's story about building his house with a large budget but facing serious problems after three years highlights the importance of upfront design. If Mike's house had been built with a solid foundation and a well-thought-out architecture, issues like cracks in the walls and disorganization would not have occurred. Similarly, in software development, core services play a vital role in directly interacting with the database and are often called by many modules. If not designed well, core services can become bottlenecks in the system.

Image

A core service not only supports a small amount of requests but also needs to handle a large volume of concurrent requests. For example, if your core service can only handle 100 requests per second (RPS) but your system needs to handle 500 RPS, you will encounter performance issues. The lack of scalability will lead to slow systems, service disruptions, and poor user experience.

Core services often interact directly with the database, so their design needs to consider efficient data retrieval and processing. A poorly designed architecture can lead to database query bottlenecks, reducing the overall system performance. Issues like cracks in Mike's house can be compared to performance issues in core services when they are not designed with scalability and optimization in mind.

To address this issue, adopting a highly scalable architecture is crucial. A prime example is Function-as-a-Service (FaaS). FaaS allows you to build and deploy independent functions that can automatically scale based on demand. This is similar to rebuilding Mike's house with separate rooms that can be easily expanded when needed.

Image

The story of Mike and his house is a clear illustration of building core services with a sound architecture. Just as a house needs a solid foundation and a well-designed structure to ensure stability and comfort, core services also require a suitable architecture to ensure the performance and scalability of the software system. Adopting architectures like FaaS can improve scalability and resource management, thereby enabling the system to operate more efficiently and be ready to meet high demands in the future.

2.3 Component Coupling

In programming, coupling refers to the degree of interdependence between components or modules within a system. When components have high coupling, they are tightly dependent on each other, which can reduce the system's flexibility and maintainability. Conversely, when components have low coupling, they operate more independently and can be easily changed without affecting other parts of the system.

Image

Reducing coupling in programming helps create systems that are easier to maintain and extend. Similar to Mike's house, where the rooms and functional areas are poorly designed and tightly interconnected, software components should also be designed to be independent and easy to change. This minimizes problems when modifying or extending the system, much like how Mike needs to rebuild his house to fix its current issues.

When Mike designed his house, building adjacent rooms that shared a common load-bearing wall is an example of high coupling. This makes expansion or renovation difficult, similar to how software components with high coupling can make it challenging to modify the source code or add new features.

Image

The lack of organization and arrangement in Mike's house leads to inefficient use of space and makes it difficult to find items. In programming, high coupling can result in code that is hard to read, maintain, and prone to errors when changes are made. This is like how Mike's house is not divided into well-defined functional areas, making it inconvenient and difficult to manage daily life.

The lesson from Mike's story is that designing and building a system (or a house) requires careful consideration of how components are interconnected. Just as Mike needs to rebuild his house to fix its current problems, software developers must pay attention to reducing coupling to create systems that are more maintainable, extensible, and efficient.

2.4 Bottleneck

One of the most obvious issues in Mike's house is the narrow hallway, which makes it difficult to move around, especially when there are many people. This not only affects the comfort but also reduces the efficient use of space.

The house is not divided into clear functional areas such as living area, sleeping area, and lacks storage space. This leads to inconvenience in finding items and managing space, making the house cluttered and difficult to use.

Image

To solve the problem of the narrow hallway, designing spacious and airy moving spaces is very important. The hallways should be widened to facilitate movement and more efficient use of space. If possible, consider designing secondary passages or expanding the area of the rooms to reduce congestion.

Changing or renovating the main load-bearing walls should be done with the advice of structural engineers to ensure that the structure is not affected. It is necessary to design flexible elements in the structure to easily expand or change without reducing the stability of the house.

To enhance comfort and organization, it is necessary to divide the house into clear functional areas. Dividing the space into living areas, sleeping areas, and storage areas will help manage the space better and make the house tidier. Adding storage rooms or closets is also a good solution to keep the living space always neat and easy to find items.

The story of Mike's house is a clear illustration that space design and organization play an important role in creating a comfortable and efficient living environment. Design bottlenecks can lead to inconvenience and difficulty in using space, but with proper attention and improvement, we can create better living spaces and avoid similar problems in the future.

2.5 Lack of Caching Strategy

In Mike's story, the absence of temporary storage spaces in his house made finding items difficult and time-consuming. This can be likened to the lack of a caching strategy in a software system.

Image

A caching strategy is a method of temporarily storing data for faster access in the future. If a system lacks effective caching, users will have to request information from the primary source, which is similar to Mike having to search around the house for items without storage. As a result:

  • Poor Performance : Accessing uncached data can degrade performance, just like it takes more time to find items in a house without storage.
  • Increased System Load : If a system doesn't utilize caching, every data request will have to be processed from scratch, putting additional load on the system, similar to walking around the house multiple times.

Image

To improve performance, systems should be designed with appropriate caching solutions, such as in-memory cache or temporary disk storage. This helps reduce data access time and increases system efficiency.

2.6 Stateful service

Similarly, in software development, especially when working with microservices or systems with many components, the lack of specialization and clear division can lead to complexity in system scaling and maintenance. Having the bathroom and kitchen share a common wall can cause problems when needing to modify or expand one room while affecting the others. Similarly, in software systems, not organizing services or resources clearly can lead to conflicts when making changes or expansions.

In Mike's house, the lack of specialization and improper organization prevents easy and efficient expansion. Similarly, in software development, when a system is not designed with good principles such as clear division of resources and services, scaling the system can be difficult and lead to inconsistencies.

Image

When a software system is not clearly divided, scaling and distributing resources can become complex. For example, in a system containing many cronjobs or stateful variables, scaling can lead to data inconsistency if not managed effectively. This is similar to how Mike's house has difficulty expanding space due to its unreasonable design.

To overcome this issue, software system design needs to focus on clearly dividing services and resources. Using principles like microservices and effective resource management models can help minimize issues related to scaling and maintaining system consistency. Applying methods like containerization can help manage services and resources more effectively, reduce interdependencies, and improve system scalability.

3. Conclusion

Mike's story and his home serve as a valuable lesson on the importance of specialized and efficient design and organization. In software development, similar principles must be applied to ensure that systems are scalable and maintainable. By learning from past mistakes and applying appropriate solutions, we can build more robust and sustainable software systems in the future.

If you have any questions or concerns, please leave a comment below.

Read posts more at : The secrets that no one tells you about why your system can not scale up?

Top comments (0)