The context
The context
The client provides eKYC SaaS APIs (face matching, OCR and more) to B2B customers through an Android SDK. A deployment for a major Indian telecom had to scale to 2 million API requests a day.
The stack was a Go API, Python machine-learning models, RabbitMQ, MinIO blob storage and PostgreSQL, deployed with Docker on Google Cloud using Nomad and Consul.
The client provides eKYC SaaS APIs (face matching, OCR and more) to B2B customers through an Android SDK. A deployment for a major Indian telecom had to scale to 2 million API requests a day.
The stack was a Go API, Python machine-learning models, RabbitMQ, MinIO blob storage and PostgreSQL, deployed with Docker on Google Cloud using Nomad and Consul.
The challenge
The challenge
GPU costs at go-live: Pilot costs were $5K a month. Go-live traffic was expected to be 20 to 30 times higher, and GPU VMs made up 90% of the bill, which pointed to about $100K a month without autoscaling.
GPU costs at go-live: Pilot costs were $5K a month. Go-live traffic was expected to be 20 to 30 times higher, and GPU VMs made up 90% of the bill, which pointed to about $100K a month without autoscaling.
GPU costs at go-live: Pilot costs were $5K a month. Go-live traffic was expected to be 20 to 30 times higher, and GPU VMs made up 90% of the bill, which pointed to about $100K a month without autoscaling.
Business-hours availability: Services had to stay at 99% availability from 8 am to 10 pm.
Business-hours availability: Services had to stay at 99% availability from 8 am to 10 pm.
Business-hours availability: Services had to stay at 99% availability from 8 am to 10 pm.
The impact
The impact
90% lower cost: Monthly cloud spend stays under $10K, against about $100K without the autoscaler.
90% lower cost: Monthly cloud spend stays under $10K, against about $100K without the autoscaler.
90% lower cost: Monthly cloud spend stays under $10K, against about $100K without the autoscaler.
90% lower cost: Monthly cloud spend stays under $10K, against about $100K without the autoscaler.
2+ years in production: The system has run in production since go-live.
2+ years in production: The system has run in production since go-live.
2+ years in production: The system has run in production since go-live.
2+ years in production: The system has run in production since go-live.
The approach
The approach
In the final Auto Scaling solution, we needed a manual override option. At that time, both Nomad and Kubernetes did not provide this capability out of the box. Also, migrating to Kubernetes would have meant much rework for the entire team. Hence, we decided to build a custom auto-scaling solution on top of Nomad and existing toolchains used in the project.

Autoscaler runs every 20 minutes, predicts the traffic for the next cycle and ensures that required ML workers are available. Same logic works for scale up as well as scale down.
Some of the other challenges we encountered were as follows:
Eliminate single points of failure
Run RabbitMQ in High Availability mode with queue replication across three zones in GCP.
Use GCloud Storage as a fallback for Minio. If Minio is unavailable, the application will transparently use GCloud Storage as an image store.
ML workers were split across two availability zones in an odd-even fashion.
For other components (PostgreSQL, Redis, API), we used SaaS offerings by GCP and ran redundant versions of those components.
GPU utilization bug in Nomad (https://github.com/hashicorp/nomad/issues/6708)
We used Raw Exec driver from Nomad and launched multiple ML containers on a single VM using docker-compose.
We also implemented custom health checks and CPU stickiness for individual containers.
Capacity Planning
We figured out the optimal VM setup considering factors like GPU, RAM, and cost per hour.
We studied past request patterns and figured out a simple formula for predicting traffic based on a slope of the request growth line.
Automated Rolling Deployments during peak time
We pre-fetched the ML worker docker images (7GB+) on nodes to have a faster startup time during deployments.
The golden image would be updated on the first node. After it is successfully deployed, it would be updated on all remaining nodes, one at a time. This allowed us to deploy services even during peak load.
Monitoring, Alerting, and auto-healing
We made various SLI reports and latency dashboards available to all stakeholders.
Setup PagerDuty and on-call schedules.
Implemented scripted actions for common operation issues (example: Handling Live VM migration for GPU VMs)
Test the whole setup and fix issues
We Performed extensive, long-running Load tests with production-like traffic patterns to ensure the Autoscaler worked as expected.
Tested redundancies and HA setup by introducing chaos (shutting down of nodes and services like Minio) during load testing.
Tech stack used.
Watch this talk for a detailed understanding of the work, presented at HashiTalks India 2021.

In the final Auto Scaling solution, we needed a manual override option. At that time, both Nomad and Kubernetes did not provide this capability out of the box. Also, migrating to Kubernetes would have meant much rework for the entire team. Hence, we decided to build a custom auto-scaling solution on top of Nomad and existing toolchains used in the project.

Autoscaler runs every 20 minutes, predicts the traffic for the next cycle and ensures that required ML workers are available. Same logic works for scale up as well as scale down.
Some of the other challenges we encountered were as follows:
Eliminate single points of failure
Run RabbitMQ in High Availability mode with queue replication across three zones in GCP.
Use GCloud Storage as a fallback for Minio. If Minio is unavailable, the application will transparently use GCloud Storage as an image store.
ML workers were split across two availability zones in an odd-even fashion.
For other components (PostgreSQL, Redis, API), we used SaaS offerings by GCP and ran redundant versions of those components.
GPU utilization bug in Nomad (https://github.com/hashicorp/nomad/issues/6708)
We used Raw Exec driver from Nomad and launched multiple ML containers on a single VM using docker-compose.
We also implemented custom health checks and CPU stickiness for individual containers.
Capacity Planning
We figured out the optimal VM setup considering factors like GPU, RAM, and cost per hour.
We studied past request patterns and figured out a simple formula for predicting traffic based on a slope of the request growth line.
Automated Rolling Deployments during peak time
We pre-fetched the ML worker docker images (7GB+) on nodes to have a faster startup time during deployments.
The golden image would be updated on the first node. After it is successfully deployed, it would be updated on all remaining nodes, one at a time. This allowed us to deploy services even during peak load.
Monitoring, Alerting, and auto-healing
We made various SLI reports and latency dashboards available to all stakeholders.
Setup PagerDuty and on-call schedules.
Implemented scripted actions for common operation issues (example: Handling Live VM migration for GPU VMs)
Test the whole setup and fix issues
We Performed extensive, long-running Load tests with production-like traffic patterns to ensure the Autoscaler worked as expected.
Tested redundancies and HA setup by introducing chaos (shutting down of nodes and services like Minio) during load testing.
Tech stack used.
Watch this talk for a detailed understanding of the work, presented at HashiTalks India 2021.

In the final Auto Scaling solution, we needed a manual override option. At that time, both Nomad and Kubernetes did not provide this capability out of the box. Also, migrating to Kubernetes would have meant much rework for the entire team. Hence, we decided to build a custom auto-scaling solution on top of Nomad and existing toolchains used in the project.

Autoscaler runs every 20 minutes, predicts the traffic for the next cycle and ensures that required ML workers are available. Same logic works for scale up as well as scale down.
Some of the other challenges we encountered were as follows:
Eliminate single points of failure
Run RabbitMQ in High Availability mode with queue replication across three zones in GCP.
Use GCloud Storage as a fallback for Minio. If Minio is unavailable, the application will transparently use GCloud Storage as an image store.
ML workers were split across two availability zones in an odd-even fashion.
For other components (PostgreSQL, Redis, API), we used SaaS offerings by GCP and ran redundant versions of those components.
GPU utilization bug in Nomad (https://github.com/hashicorp/nomad/issues/6708)
We used Raw Exec driver from Nomad and launched multiple ML containers on a single VM using docker-compose.
We also implemented custom health checks and CPU stickiness for individual containers.
Capacity Planning
We figured out the optimal VM setup considering factors like GPU, RAM, and cost per hour.
We studied past request patterns and figured out a simple formula for predicting traffic based on a slope of the request growth line.
Automated Rolling Deployments during peak time
We pre-fetched the ML worker docker images (7GB+) on nodes to have a faster startup time during deployments.
The golden image would be updated on the first node. After it is successfully deployed, it would be updated on all remaining nodes, one at a time. This allowed us to deploy services even during peak load.
Monitoring, Alerting, and auto-healing
We made various SLI reports and latency dashboards available to all stakeholders.
Setup PagerDuty and on-call schedules.
Implemented scripted actions for common operation issues (example: Handling Live VM migration for GPU VMs)
Test the whole setup and fix issues
We Performed extensive, long-running Load tests with production-like traffic patterns to ensure the Autoscaler worked as expected.
Tested redundancies and HA setup by introducing chaos (shutting down of nodes and services like Minio) during load testing.
Tech stack used.
Watch this talk for a detailed understanding of the work, presented at HashiTalks India 2021.

Download this case study
Download this case study
A PDF version to read later or share with your team.
A PDF version to read later or share with your team.









