Cost Optimization with AWS Reserved Instances at Innovid

Aran Pauker
Innovid
Published in
4 min readJan 14, 2019

--

Amazon’s Reserved Instances (RIs) is a great solution for cost reduction for your cloud infrastructure’s heavily used resources (EC2, RDS and Redshift) and especially for making your executive management happy at the end of each month. If used wisely, it can cut your EC2 expenses by as much as 40% annually. Careless usage, on the other hand, might lead to catastrophic results of even six (!) times higher expenses.

The good, the bad…

The following tables demonstrate the power of this feature, with varying periods of real usage.

TL;DR — The use case below shows that reserved instances purchase will become fruitful only after eight months of non-stop usage (see Table 2), with maximal discount achieved after a full year (Table 3).

Say, for example, that you are happily reserving your c4.large instance as a one year with partial upfront payment, but unfortunately it was terminated one month later due to lack of use (see Table 1). You paid $525 for that reserved instance (distributed yearly, no cancellation) vs. only $72 had you “known” in advance that it will be terminated soon and used an on-demand instance instead. You just lost $453

Now, take those $453 and multiply it by your instances count — I got your attention now, have I?

Table 1: One month of instances running, Reserved vs. On-Demand Pricing
Table 2: Eight months of instances running, Reserved vs. On-Demand Pricing
Table 3: Full year of instances running, Reserved vs. On-Demand Pricing

And the ugly…

Sadly, among the many cost optimization tools Amazon has to offer (Trusted Advisor, Budgets, Cost Explorer, etc.), there’s nothing that can stop you from paying all of your savings to Amazon over non-existing instances.

True, you can get alerted when your RI purchase is about to be retired, or when your RI utilization or coverage are low, but this would be too late (you’re already stuck with that RI) or too early to execute (remember the $453 gone down the drain due to early termination?).

So, it’s a bit like playing the roulette — are you ready to place your bets? Cold feet suddenly, ha?

No worries — Innovid is here to help!

At Innovid, the world’s leading Video Marketing Platform, we decided to take action and create a tool that will allow us to track and optimize our RI purchases. We are also planning to open source this tool for the AWS community, so stay tuned to our blog.

For that purpose, we created a “baseline”, which is the list of instances that we know should remain up and running for at least 8 months and is reviewed on a quarterly basis by the DevOps team and our Engineering leads. These instances must be covered with RIs. Instances that are not included in that list are considered transient and therefore not entitled for RI coverage.

This tool was automated to be executed on a weekly basis and, using the baseline (see Table 4), produces the following:

  1. RI purchase required for non-covered baseline instances (see Table 5).
  2. Unused RIs which can be sold in the AWS RI Marketplace.
  3. Active instances not covered by the baseline.
  4. Baseline instances that are no longer active.

The first two outputs are an immediate call to action — either buy or sell RIs. The last two outputs are used in the baseline’s review process — filter out obsolete instances and consider adding recently activated instances.

Table 4: Baseline — example
Table 5: Reservation required for non-covered baseline instances — example

How is all this magic happening?

The tool, written in Python, is performing the following steps for each region and instance type (since we’re not using Convertible RIs, the purchase is regional and instance family type specific):

  1. Detect only active instances out of the baseline.
  2. Transform the active baseline instances into their normalized amount representation.
  3. Query all RIs in all the accounts that are consolidated under the payer account and transform them into their normalized amount representation.
  4. Calculate the difference between the numbers in steps 2 and 3.
  5. Emit all the relevant outputs.

Pretty cool, right?

There’s even more to it, like RDS and Redshift RI coverage calculation, with some new features in the pipe (e.g., recommending highly utilized instances that should be added to the baseline).

So if you’re planning to use (or already using) AWS’s reserved instances mechanism, and you want to do it wisely — this post is your starting point.

--

--