Scaling Artificial Intelligence on a Budget: Running a Neural Network on 100 Million Images for…
Luke Jenkinson · 27 September 2024 · 5 min read
Scaling Artificial Intelligence on a Budget: Running a Neural Network on 100 Million Images for Just $100

Street Group is the leader in the prop-tech industry in the UK. At the core of all of our products is Kraken, our advanced property information internal API. This system collects, processes and serves billions of data points about properties in the UK.
One of the types of data we collect is images of properties listings. For several of our products and in-house machine learning models, it’s beneficial to identify and extract specific features of the images, for instance: the room of the house. To build this capability, computer vision models were developed that were able to identify key features of the images.
Initially, a scalable solution was developed for applying the model to the 100k plus images that we were collecting every day. However, when we created a cost estimate for running inference on the 100 million backdated images through the same system, the cost was approximately $40k, which we didn’t think was justifiable. A study of the literature revealed a lack of suitable methods for running such a large batch inference job. Google Cloud Platform (GCP) and Amazon Web Services (AWS) both have products for batch inference, however, they would also be too expensive for the quantity of images we possessed.
Given these issues, it was decided that an in-house solution would be developed, with an emphasis on reducing the cost of any solution we created. One way to reduce costs on a cloud environment such as GCP is to use preemptable (sometimes called “spot”) instances. These instances give large discounts on unused capacity, but are able to be reclaimed by the provider at any time and thus are only suitable for fault tolerant workloads. This was a perfect compromise for our work and significantly reduced the cost of running our inference. At the time of execution, Nvidia T4 GPUs had a 90% discount for running in spot mode compared to running in normal mode. This meant that they cost just $0.05 per hour, per GPU.
Based on our idea to use spot instances, there were a number of requirements that our system would have to have:
- The system needed to handle many thousands images per second.
- The system needed a way that ensures that if an instance fails or gets preempted, it would handle it gracefully.
- The system needs to be low cost.
Based on those requirements, a solution was created utilising Kubernetes, Pub/Sub and BigQuery. A Pub/Sub queue of image names was created, a set of pods on a kubernetes cluster read from this queue, loaded the image from Cloud Storage, preprocessed the image and then sent the processed image to an inference pod running with a GPU. This pod applied the model to the image and returned the model output to the first pod. This pod then used the BigQuery “Storage Write API” to write the model output to a BigQuery table. A diagram is shown below:

Each of these components were chosen for their alignment with the requirements along with their low cost:
Kubernetes is a cloud native container orchestration platform that automates the management and deployments of containers across a cluster of nodes. This platform is well suited for our task:
- Kubernetes allows for easy scaling to very large clusters, it is (almost) as easy to run on 1 server, as it is to run on hundreds. Our final cluster for running inference had 600 distinct nodes with 100 GPUs
- Kubernetes provides built-in fault tolerance: gracefully handling the restarting of containers that have failed. This is particularly useful for us as we are running on preemptible instances and thus, over the multiple hours that this batch inference was running, many nodes were preempted.
Pub/Sub is GCP’s managed, scalable message passing service. In our system it is used to hold a queue of image URIs which the worker pods are able to read from. Pub/Sub had a number of advantages for our system:
- Low cost: Our cost for sending 100 million messages was just $4.
- High throughput: pub/sub can handle up to 4 million of our messages per second, much larger than the 15k images per second that the system processed at.
- Fault tolerant: messages will not be taken off the queue until explicitly acknowledged. Thus, if a pod is preempted during execution, the image can be retried.
BigQuery is GCP’s managed data warehousing solution, an extremely powerful solution for working with petabyte-scale data. BigQuery had a advantages for our system:
- High throughput: BigQuery storage write API can handle over 3 million writes per second. As with Pub/Sub this far exceeded our usage.
- Low cost: the BigQuery Storage Write API costs just $0.025 per GB written. In for the data we wrote. This cost less than $0.30 total in our use case.
Based on this design, we were able to spin up a large cluster of 600 nodes of which 100 had GPUs attached to them. This solution was able to process a peak of 12 thousand images per second, with large scope to increase this further. The limiting factor in this solution is the availability of GPUs within GKE. On subsequent uses of this system, GCP was unable to provision the requested number of GPUs. However, if GKE were able to supply the GPUs, this solution could be scaled up to 30x and thus process in excess of 350k images per second.
The solution that was built worked very well and produced results at a much lower cost than could have been achieved using managed batch inference systems. Since this work was concluded, the system has been used for multiple batch inference jobs and each time has provided a quick and cost effective solution to our needs. It is hoped that this article will guide the reader in building their own cost effective batch inference system.
To find out more about life at Street Group, follow us on LinkedIn, see what our team are saying on Glassdoor, or visit our careers site.






