Opens in a new tab

Explore AI Summary

Share post on:

Serving requests to thousands of ML models

Author: Irving Chen

At Sift, we’ve found that the best approach to fraud detection combines a variety of models. Some models are trained on a…

Sift Author Logo
Ankush Walhekar
black-dot
Press-Release-Tile-Image-Color-Pills_Blue

Author: Irving Chen

At Sift, we’ve found that the best approach to fraud detection combines a variety of models. Some models are trained on a single customer’s data, some models are trained on data from all customers, and some models are trained on something in between (customer cohort models). We also use several different types of models with a variety of training objectives. All in all, this means we’re running thousands of individual models at any given moment. In this blog post, we discuss some of the cracks that started showing in the system that serves all of these models, as well as a major rework of the system that we recently completed in order to keep things running smoothly.

Release cadence, startup times, and an underwhelming experimentation ecosystem

Prior to the migration, all of our models were served by a single Java service; we’ll call this the legacy inference service. A key detail about this service is that it was tightly coupled to our model training pipeline. The training pipeline is a massive Airflow DAG that retrains thousands of models at once, and the legacy inference service was coupled to this pipeline such that one instance of the service could only serve the set of models trained in a single run of the pipeline. Serving two different sets of models required a second instance of the service.

This tight coupling between the training pipeline and the legacy inference service eventually became the limiting factor in several use cases. For example, suppose we wanted to bring a new customer onboard and train just a handful of models on their data in isolation; even in that scenario, the only option was to run the full pipeline and stand up an entirely new instance of the service. In practice, that wasn’t economically viable, and so we found ourselves stuck on a monthly model release cadence. Additionally, just keeping multiple instances of the same service running became an operational headache, because any code changes or updates to the service had to be rolled out to multiple service fleets instead of just one.

Legacy inference service overview

To address those pain points, we wanted to rework the legacy inference service to remove this coupling. Instead of only being able to serve a single set of models, the service should provide a framework for serving all our models together. This was made difficult by a second key detail about the legacy inference service, which is that it loads its set of models into memory at startup.

While each individual model is relatively small by modern standards, thousands of them still add up. At its peak, the service’s max heap was set to 18 GB and the model load sequence was taking around two minutes. Combining multiple sets of models would increase the memory requirements and startup time proportionately. We’ve seen up to five sets of models running at the same time, which would mean a 90 GB max heap and 10 minute model load sequence. We were concerned that such a heavy footprint would impact the quality of our service, for example, by taking too long to autoscale in response to a fraud attack.

One last detail about the legacy inference service is that it served models with in-house preprocessing and inference code. This made it almost impossible to faithfully reproduce production results in our analysis environments—Databricks and Snowflake—which primarily support Python and SQL development. Similarly, experimental results from our analysis environments could only be productionized with considerable effort in translating them to Java. We were effectively walled off from iterating on our core modeling stack.

Taken together, the fixed release cadence, poor startup times, and an underwhelming experimentation ecosystem all pointed in the direction of a comprehensive rework of this service.

Building our model serving framework

Modern ML practitioners will recognize that the widely accepted solution to this class of problems is a model serving framework. However, we have an unusual combination of model serving requirements, including shadow traffic, model ensembles, and post-inference calibration. Model ensembles and calibration are also fairly dynamic: we need to be able to tweak the mixing weights and calibration parameters throughout the model release process. Our survey of readily available model serving frameworks didn’t find anything that quite fit this description, so we set out to build one ourselves. The architecture for our framework can be broken into three layers: model containers, container orchestration, and serving.

The lowest layer is the model container. Separating models into individual containers makes each model an independently deployable unit. This is crucial because it enables deploying one model at a time instead of one thousand, a much faster and simpler operation. The main challenge with containerizing the existing Java inference code was in cleanly separating inference code from the rest of the legacy service. The legacy inference service had accrued some micro-optimizations over time that tightly coupled inference across different models (i.e., spaghetti code). We had to refactor significant portions of code to allow for more modular data injection points, as well as to conform to the API that we defined for communication between model servers and serving layer clients.

The next layer up is container orchestration. For this layer, we initially trialed GCP’s Vertex AI online prediction offering. This offering takes several forms: public endpoints, private PSC endpoints, and private services access endpoints. We tried all three, but none met our latency requirements, so we pivoted to deploying our model containers directly on GKE. Our client services and model endpoints all sit in the same Kubernetes cluster, so it’s easy for requests to go through the service mesh. We also have a well-established pattern of using gRPC for inter-service communication that was easy to apply for this use case.

The last layer is the serving layer. As mentioned above, we have an unusual combination of requirements for this layer that we set out to satisfy ourselves. This involved a ground-up rewrite of the request orchestration business logic of the legacy inference service, restructured to decouple it from the monolithic training pipeline so that there is just one instance of the service. To simplify deployment operations, we also added support for real-time updates to model configuration as part of this rewrite, reducing the rollout time of new configuration from hours to minutes.

Model serving framework overview

Results and what’s next

In June, we completed this complex, multi-year migration. The surface area of the migration extended even beyond what was discussed in this blog post: we also introduced event-driven architecture to Sift as well as a new micro-service responsible for online updates to model parameters.

As a result of the migration, day-of-deployment operations for model release now take only minutes, and time saved throughout the release process as a whole has given us an extra 48 hours of calibration data “for free.” Our scoring services are no longer on the verge of running out of memory every month. Most importantly, we’ve unlocked a net-new set of capabilities: we can now deploy models trained with any ML framework in any language, and at an arbitrary cadence. In July, we used this new capability to release a model trained in a standard Python notebook directly to production for the first time in Sift history.

But there’s still work to be done! The training pipeline itself still limits our general model release cadence, and our model serving framework is still missing the kind of easy-to-use configuration system that is found in any off-the-shelf model serving framework. If you’d like to help us solve these problems, we are hiring!

Dare to grow differently.

Flip the switch on fraud-fueled fear. Make risk work for your business and scale securely into new markets with Sift’s AI-powered platform.

see sift in action
  • remitly
  • swan
  • yelp-white
  • taptap
  • remitly
  • swan
  • yelp-white
  • taptap