Cleaning up your microservice resources

Home Blog Cleaning up your microservice resources

Managed services and serverless deployments have become increasingly popular tools in the software development process. This means that organizations are focusing less on infrastructure resources and more on the functionality and security of applications. Managed services—such as the applications like DynamoDB, Step Functions and API Gateway that are crucial to serverless architectures—come with associated costs. While these costs appear to be minimal at first glance, it is essential to keep them in check as they can accumulate into an unnecessary overhead expense over time. Costs can spiral for a variety of reasons:

  • APIs calls are not kept in check and end up using more resources than required. 
  • Resources required for running the application are overallocated and therefore underutilized.
  • Enterprises haven’t cross checked the cost for the service across regions. Costs across regions vary, and while differences are generally minimal, over a number of applications they still add up.
  • Cloud resources have been provisioned for the enterprise but remain partially unused. When scaling up, most enterprises have a hard time tracking all their resources. These unallocated resources might be replicated across regions, which adds up to the cost.

This article will discuss three effective ways to mitigate unnecessary costs by controlling resource consumption of microservices using observability.

Continuously Monitor Resource Usage of APIs

APIs form the backbone of any application, and interact with numerous services. Before the advent of managed services, APIs used to have their own infrastructure, which was a burden on engineers who had to divide their attention between the health of the servers and adding functionality to the API. Today, cloud services such as AWS Lambda and AWS Elastic Container Service (ECS) can help to maintain the infrastructure’s health and security, so that engineers can focus on developing the API alone.

While these managed services are an asset to developers, their costs need to be kept in check. More resources utilized means more costs incurred. So how can you ensure that these costs are kept under control?

Tracking all metrics pulled from observable data is a good starting point. These figures can give us a reasonable estimate of the API usage. The metrics can be leveraged to design resource-efficient APIs to help set exact limits for the microservices. As a result, these measures can help us significantly when it comes to saving on infrastructure costs for APIs.

Best Practices for Writing APIs

Following best practices when writing APIs can reduce execution time to limit costs further: 

  • Avoid using recursive code to prolong execution.
  • Minimize the complexity of dependencies so that the code can load quickly in the execution environment.
  • Cache API responses to increase data retrieval performance and reduce cost at scale. If caching is applied, database instance scaling can be minimized, thus saving costs in provisioning the database servers.

Refine Infrastructure Resource Allocation

Many enterprises over allocate resources for critical production applications to be on the safer side, even after passing a rigorous performance testing analysis indicating that fewer resources are required. After the successful deployment of the applications, businesses forget to monitor how many resources the application consumes to work efficiently, and thus continue paying for overallocated resources. This contributes to potentially huge and unnecessary costs.

For example, your Lambda function might have been allocated to process files of several gigabytes, but in reality your application might be processing files of a much smaller size—say, up to a few megabytes. The overall resources reserved for the Lambda function were overestimated, unmonitored, and now translate to an additional cost.

Observability for Your Application’s Resource Consumption

Resource consumption metrics for production-facing applications should be continuously monitored after deployment through observability. Observability data gives a rough estimate of how many resources are actually consumed by your applications. Monitoring the performance of your applications and their resource consumption with Lumigo can help with optimizing resource utilization. You can then share these findings with your team as part of your regular review process in order to reduce idle and unallocated costs, or you might even be able to create savings yourself.

Identify Unused Resources Being Deployed

On any given day, multiple cloud resources are provisioned for various purposes, primarily for temporary functions like testing or scaling. However, engineers can sometimes forget to bring down the instances after the temporary task’s completion, leading to resources lying unused but still being billed.

Let’s say that you are testing out a new feature for your application, and specific resources are allocated to your team for this specific purpose. After a few weeks of testing and deploying in production, the infrastructure provisioned for testing is no longer required and might be forgotten about. As a result, it lies unused in the environment.

This is a widespread issue, since many enterprises do not track cloud resource usage. Unused resources add significant costs to the organization. Lumigo facilitates careful monitoring of your development environments to ensure that unused resources are cleaned up when they are no longer needed.

Strategize for Efficiency Savings

Using managed services allows engineering teams to focus on innovation rather than infrastructure. However, if not kept in check, their associated costs can make a huge dent on the organization’s budgeting strategy. Having strategies in place to reduce and clean up microservice resources can lower a business’ costs, sometimes substantially.

Manual cost optimization can be a daunting task. Obtaining accurate observable data is an important first step towards understanding where savings can be made without compromising on performance.

Clean Up Your Resources with Lumigo

Lumigo can seamlessly navigate the most complex serverless and containerized environments and collect end-to-end observable data through automated distributed tracing. Lumigo presents your data on dynamic dashboards, providing you with all the information you need to perform automated cost optimization.

Clean up your cloud resources today. Get started with a free trial of Lumigo.