How IPONWEB Adopted Spot Instances to Run their Real-time Bidding Workloads
AWS Architecture BlogHow IPONWEB Adopted Spot Instances to Run their Real-time Bidding Workloadsby Roman Boiko | on25 AUG 2021| inAdvanced (300),Amazon EC2,Architecture|Permalink|ShareIPONWEBis a global leader that builds programmatic, real-time advertising technology and infrastructure for some of the world’s biggest digital media buyers and sellers. The core of IPONWEB’s business is Real-time Bidding (RTB). IPONWEB’s platform processes, transmits, and auctions huge volumes of bid requests and bid responses in real time. They are then able to determine the optimal ad impression to be displayed to an end user.IPONWEB processes over 1 trillion impression auctions per month. The volumes of impressions require significant compute power to make calculations and complete the entire bidding auction within 200 milliseconds. IPONWEB’s flagship RTB products,BidSwitchand BSWX, have been running onAmazon EC2reserved and On-Demand Instances. The nature of the workload for this volume of compute for this short a time, has been notably spiky. IPONWEB maintained a core workload running 24/7 on EC2 instances covered byReserved InstancesandSavings Plans.To optimize costs further, IPONWEB decided to useAmazon EC2 Spot Instances. Although this decision is also advantageous for workload efficiency, adopting Spot Instances did introduce a few challenges that needed to be addressed.Some challenges in using Spot Instances for this use caseThe Real-time Bidding (RTB) workload is critical to the business.Any interruption of bid processing has a negative impact on revenue. While the spikiness issue needed to be addressed, it was imperative to find a solution that could be implemented in a smooth and seamless fashion.Efficient distribution over Availability Zones (AZs) within the AWS Region being used was imperative.RTB auctions process trillions of requests and consume large volumes of network traffic. Consequently, IPONWEB is continuously optimizing traffic costs along with compute costs. The architectural approach is to put as much workload as possible in one AZ to reduce inter-AZ traffic. For better performance, IPONWEB’s main MongoDB database and Spot Instances are running in the same AZ.Under certain circumstances, using Spot Instances in other AZs can still be a good choice. AWS charges for traffic between AZs, so IPONWEB defined a break point. This occurs when usage of an EC2 Spot Instance in adifferent AZ became equal tousage of an EC2 On-Demand Instance in the same AZ.This break point calculation led to the following best practices (in order of most value to least, for this use case):The most efficient practice was to run Spot Instances in the same AZ as the databaseNext effective was to run Spot Instances in the other AZsThe third option was to run On-Demand Instances in the same AZLeast effective was to run On-Demand Instances in the other AZsIPONWEB’s solutionIPONWEB evaluatedAuto Scaling groupsusing both Spot and On-Demand Instances. They concluded that using Auto Scaling alone would not satisfy all the requirements, and it would be difficult to distribute workloads between AZs adequately. This is because an Auto Scaling group tries to distribute the instances across all the AZs evenly. However, IPONWEB needed to scale in one AZ initially, to avoid unnecessary cross AZ traffic. In addition, one Auto Scaling group can’t compensate for the sudden termination of a large number of Spot Instances. IPONWEB created a more flexible and reliable solution based on using four Auto Scaling groups.The first Auto Scaling group runs only on Spot Instances in the same AZ as the main database application.The second Auto Scaling group is running only Spot Instances in the other AZs.The third Auto Scaling group is running EC2 On-Demand Instances in the database AZ.The fourth Auto Scaling group is for EC2 On-Demand Instance on the other AZs.The application workload running on the instances in these four Auto Scaling groups is evenly distributed. This is done using anApplication Load Balancer (ALB), or IPONWEB’s purpose-built load balancer.Figure 1. Spot and On-Demand Instances scaling by different AZsIPONWEB then needed to create a proper scaling policy for each Auto Scaling group. They decided to implement a self-monitoring mechanism in the application. This monitored how much compute resources (CPU and memory) are still available at any given time. Using this information, the application determines if it is able to take the next processing request. If it’s unable to, a log entry is created, and an “empty” response is returned. IPONWEB created a composite metric based on the drop rate and CPU utilization of each host.IPONWEB used that custom metric to create scaling policies for every Auto Scaling group. Each Auto Scaling group has a specific threshold. This provides granular control, such as when, and under what conditions the particular Auto Scaling group scales-out or scales-in. It will set a lower threshold for the first Auto Scaling group and higher thresholds for the next Auto Scaling groups.For example, the group with Spot Instances in the same AZ starts scaling at 75% utilization. The group with Spot Instances in other AZs starts scaling at 80% utilization.Because each instance in every group receives the same number of incoming requests to process, the first group will be scaling earlier than the others.If some Spot Instances are shut down in the first group, then the total utilization will increase, and the second group will begin scaling.If there is a shortage of Spot Instances in other AZs as well, then the group with EC2 On-Demand Instances will scale out.When the Spot Instances are available and can be used again, the first group will use them. Then total utilization will decrease, causing the other groups to scale in.Typically, the majority of this workload is done by the first group. The other groups are running with a bare minimum of two instances in each. After going live with this solution, IPONWEB observed that they can usually run the major portion of their workloads with the cheapest option. In this case, it was using Spot Instances in the same AZ as their database. There were several times when a large number of the Spot Instances were shut down. When this happened, the scaling diverted to On-Demand Instances. In general, the solution worked well and there was no degradation on the running services.ConclusionThis solution helps IPONWEB utilize compute resources more efficiently using AWS, to place and process more bids. After the migration, IPONWEB increased infrastructure on AWS by ~15% without incurring additional costs. This solution can also be used for other workloads where you must have a granular control on the scaling while minimizing the costs.Victor Gorelik, VP of Cloud Infrastructure at IPONWEB said:“If you use cloud without optimizations, it is expensive. There are two ways to optimize the costs – use either Savings Plans or Spot Instances. But it feels like using Savings Plans is a step back to the traditional model where you buy hardware. On the other hand, using Spots is making you more Cloud native and is the way to move forward. I believe that in the future the majority of our workloads will be run on Spot.”Read more here:Amazon EC2 Spot Instances PricingHow to use Auto Scaling with Spot InstancesSpot Instances workshopsTAGS:Amazon EC2 Spot Instances,RTBRoman BoikoRoman works as AWS Specialist Solution Architect, Serverless in Munich. He is focused on helping customers build cloud native and event-driven architectures on top of AWS. Roman has a strong background in architecting microservices applications and implementing them using DevOps practices.
IPONWEB is a global leader that builds programmatic, real-time advertising technology and infrastructure for some of the world’s biggest digital media buyers and sellers. The core of IPONWEB’s business is Real-time Bidding (RTB). IPONWEB’s platform processes, transmits, and auctions huge volumes of bid requests and bid responses in real time. They are then able to determine […]
Roman Boiko
Advanced (300) Amazon EC2 Architecture