How to optimize your Microservice Architecture for sustainability

0
1558
How to optimize your Microservice Architecture for sustainability

As of today, the important topic in businesses is sustainability. Well, yes but what are we speaking mostly? The longer we keep the lights on or the water running, the more resources we consume. That only means a bigger carbon footprint? The answer is no, It’s the same for running the software with high compute power. The more computing power and digital storage we need, the more electricity we use.

We should acknowledge and accept there is a problem. IT is a large and growing part of global warming problem; by 2030 it’s predicted that 21% of all the energy consumed in the world will be by IT. Energy that is still, for the vast majority, generated from fossil fuels. The internet accounts for 3.7% of global carbon emissions; slightly more than aviation, and we all know we need to fly less… but what will do for IT? Will consider stopping building or using, the technology? Obviously no, as it is part of the growth and requirement. 

Same time, we shouldn’t take it light; we are requesting you, consider green engineering principles while you’re building or versioning an API. Also, when you are breaking down a monolith into microservices, minimize the microservice traffic. Remove unnecessary network hops. Bring this up in decision sessions and architecture review boards. Educate your colleagues, do more of your own research. Just please don’t read this, agree with it, and then continue doing everything exactly as before.

In this post let’s check how we can apply the principles of green software to optimize our microservice architecture for sustainability. Why should give more attention to microservices architecture? here is the stat explains the adoption to microservices. 

microservice sustainability

Before we check it further, here are some terms used in this post.

  1. Carbon: Build applications that are carbon efficient.
  2. Electricity: Build applications that are energy efficient.
  3. Carbon Intensity: Consume electricity with the lowest carbon intensity.
  4. Embodied Carbon: Build applications that are hardware efficient.
  5. Energy Proportionality: Maximize the energy efficiency of hardware.
  6. Networking: Reduce the amount of data and distance it must travel across the network.
  7. Demand Shaping: Build carbon-aware applications.
  8. Measurement & Optimization: Focus on step-by-step optimizations that increase the overall carbon efficiency.

What is Microservices?

Microservices — also known as the microservice architecture — is an architectural style that structures an application as a collection of services that are.

  • Independently deployable
  • Loosely coupled.
  • Organized around business capabilities.
  • Owned by a small team.
  • Highly maintainable and testable

The microservice architecture enables the rapid, frequent and reliable delivery of large, complex applications. It also enables an organization to evolve its technology stack.

When we speak about microservice architecture, we should focus on following things, 

  • Compute
  • Count of microservices
  • Database
  • Latency
  • Network

Let’s check one by one how to optimize. 

Increase your compute utilization.

Increase your workload distribution and compute resources so that you use less resources at a higher utilization. How this helps, well, with high limit, it reduces the amount of energy your compute-resources spend in an idle state. 

  • If using virtual machines for compute resources and they have low utilization, consider reducing the size of those virtual machines to increase utilization. Smaller virtual machines with higher utilization usually use less energy than larger virtual machines with lower utilization given the same workload.
  • Evaluate migrating your workload to a PaaS wherever possible. Typically, PaaS solutions are sized more appropriately for their workload and it can run those workloads at a high utilization on their underlying compute resources.
  • Consider using auto-scaling or burst capabilities for your compute-resources over statically allocating compute resources for maximum capacity at all times. These capabilities allow you to increase and decrease your compute-resources based on demand while keeping the utilization high on those compute resources.
  • If you have many logical layers in a physical tier, consider increasing your physical tiers and reorganizing where your logical layers run. The increased physical tiers with a more granular organization of logical layers allows you more flexibility to scale the logical layers independently. This flexibility allows you to keep utilization high on your compute-resources and avoid idle logical layers.

Reduce your number of microservices.

A microservices architecture is an effective way to focus a service on a specific business domain and decentralize ownership and knowledge throughout the team or system. Ensuring the appropriate level of abstraction is important to help limit network congestion, latency, and overall complexity.

  • Consider combining services, logically or physically, where similar scale points exist to reduce the footprint of the overall architecture.
  • If two or more microservices are highly coupled, consider co-locating to reduce network congestion and latency.
  • Use languages and technology stacks that optimize the efficiency of a specific microservices function. The independence and abstraction of functionality to an API layer means you are free to make the technical decisions that maximize utilization in your technical stack for each microservice.
  • Consider running any resource-intensive microservices in a region with a lower carbon intensity.
  • Reduce the number replicas or microservices when there is zero-use. 

Optimize your database.

Optimizing which database, you use as well as how the data is stored can reduce the energy used to run the database as well decrease idle time waiting for queries to complete.

  • Ensure you are using the best database for interacting with your data set. For example, if you are running many relational queries on your data set, a relational database is better suited and likely more efficient to use than NoSQL database.
  • If no single database is designed to handle all the ways you interact with your data set, consider keeping redundant copies of your data in different databases and using each database for the subset of interactions best suited for that database.
  • Consider using index if your database offers it.
  • Consider evaluating and optimizing your queries.
  • Consider using a database cache. In some cases, caching can reduce redundant queries to the database and decrease energy usage by the database, especially for complex or compute-intensive queries.

Understand your latency limits.

In many cases, web applications are designed by default with very low latency expectations, assuming a response to a request should happen immediately or as soon as possible. This assumption can limit your options for reducing the energy usage in your application. Consider evaluating how your application is used and if you can relax the latency limits in some areas, which can increase your options for reducing carbon.

  • Consider separating certain operations outside of the request/response cycle. For example, if there is a request to send an email that blocks the response until the email is sent, you can instead asynchronously send the email using a worker process and unblock the response.
  • Consider running worker processes a lower priority than web process. This prioritization allows worker processes to run only when compute resources are not needed by web processes and keeps utilization high.
  • Consider running the worker processes in a region with lower carbon intensity.
  • Consider delaying worker process to run when the carbon intensity is the lowest.

Optimize your network traffic.

Reduce the amount of traffic your architecture creates per operation as well as the distance each request and response travels.

  • Consider using caching headers, which allows browser caches and proxy caches to have enough information to confidently cache static assets. Caching static assets at the browser or proxy level allows future requests for those assets to be handled by those caches and reduces network traffic to your application.
  • Consider using a CDN to distribute your application’s static assets closer to the source of a request. This distribution of assets reduces the distance all requests for static assets has to travel over the network.
  • Where possible, reduce the size and optimize your bundles and static assets.
  • Consider using compression and decompression for data you transmit over the network. Compression and decompression are usually taking less overall energy than transmitting uncompressed data over the network.

Consider

If you’re just starting out on microservice journey today, spend some time thinking about the sustainability of your architecture. A move towards microservices can bring your business several operational efficiencies, allowing you to consume less, become more sustainable and even save money. Also, if possible, revisit your existing architecture and see where you can optimize for more sustainability. Also, we request to explore tools like kube-green, which will help to automate some of the functions to save energy, as well as money. 

Google search engine