Mercado Tech Brasil

Ensure scalability and availability in solutions architecture: learn how

Published on · Solutions Architecture · by William Garcia

Rows of lit servers in a data center
Photo: Ranu Patel · WordPress Photo Directory (CC0, public domain)

This is article 7 of 10 in the Mercado Tech Brasil series on solutions architecture. The topic now is scalability and availability: how to make the solution handle growth and stay up when some piece fails, which always ends up happening.

Scalability and availability are not the same thing

Scalability is the ability to serve more demand by adding resources. Availability is the share of time in which the service works as expected. A system can scale very well and go down entirely because it depends on a single database; another can always stay up and freeze when volume doubles. You have to take care of both.

Scalability in solutions architecture: growing without rewriting

  • Vertical scaling: using a bigger machine. It is simple, but it has a ceiling and does not protect against failures.
  • Horizontal scaling: adding more instances behind a load balancer. It requires the application to be stateless, keeping sessions and files off the server.
  • Autoscaling: adding and removing instances according to demand, which also avoids keeping idle capacity.
  • Caching and content delivery networks: serving repeated content without reaching the server.
  • Queues: absorbing peaks and processing at a feasible pace, as we saw in the article on messaging.

Most of the time, the ultimate bottleneck is the database. Read replicas, optimized queries and partitioning come into play when the application already scales and the database cannot keep up.

Availability in solutions architecture

Eliminate single points of failure

List each component and ask: if this one goes down, what stops? A database without a replica, a single server and even a credential that only one person knows are single points of failure. Spreading instances across different zones of the cloud provider is a common measure.

Fail gracefully

When a dependency slows down, the worst thing is to wait indefinitely. Set timeouts, retries with increasing intervals and circuit breakers that stop calling a troubled service for a while. If the shipping calculator is down, maybe the store can show a default delivery estimate instead of blocking the purchase.

Agree on realistic targets

Total availability does not exist. Define indicators, such as the percentage of successful requests and response time, and internal targets for them, known as SLOs. Each extra decimal place in the target shrinks the tolerated failure window and makes the solution much more complex to operate. The target must match the real impact on the business.

Observability: the foundation of scalability and availability

You cannot keep available what you cannot see. An observable solution combines three signals:

  • Structured logs, with a correlation ID to follow an operation across systems.
  • Metrics, such as volume, error rate, response time and resource saturation.
  • Distributed tracing, which shows where a request went and where it slowed down.

Alerts should fire on the symptom the user feels, such as errors or slowness, and not on every technical fluctuation, so the team does not get used to ignoring them.

In practice

Before a peak date, such as a retailer's Black Friday, the consulting work includes load tests in an environment similar to production, a review of single points of failure and a dashboard with the agreed indicators. The goal is to find the limits in a controlled test, not on the busiest day of the year.

Read also: Apply security by design in solutions architecture: see the principles

Translated from the original in Portuguese. Read the original.