Decoupling Ad Server ad performance writes

Introduction

To decide which ads to serve, our GumGum ad server needs to make decisions not just based on different targeting requirements, but also based on other factors such as the ad goals, RPM (revenue per million), viewability, click through rate etc.

Implementation options

  1. When we receive an ad event for an impression or a viewable event we could write to our performance database ScyllaDB.
  2. Decouple writes from ad server using AWS Lambda.

What is Lambda?

AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers. AWS Lambda automatically scales your application by running code in response to each event, so you only pay for the compute time you consume, and you’re never paying for over-provisioned infrastructure.

Moving to AWS Lambda

Optimizations

We started sending around 65,000 messages per minute to our SQS queue which needs to be ingested by the Lambda. Each Lambda when started needs to initialize the DB client which takes a few seconds, so we realized cold start of Lambda won’t help us in achieving our throughput needs. So, our first step was to use provisioned capacity to keep a certain number of execution environments initialized.

Chart showing Number of Messages in queue (us-east-1 region) (very up and down with spikes)
Chart showing Number of Messages in queue (us-east-1 region) (very up and down with spikes)
Number of Messages in queue (us-east-1 region)
Chart showing Number of Lambda invocations (us-east-1 region) (very up and down with spikes)
Chart showing Number of Lambda invocations (us-east-1 region) (very up and down with spikes)
Number of Lambda invocations (us-east-1 region)
Chart showing lambda execution duration (us-east-1 region) (more consistent with only a few large spikes)
Chart showing lambda execution duration (us-east-1 region) (more consistent with only a few large spikes)
Lambda execution duration (us-east-1 region)

Conclusion

At GumGum we took on a project that required us to store performance data, and we decided to go with moving to AWS Lambda and decoupling writes using a SQS queue. After several optimizations, we were left with an optimal system that is very cost effective.