Building a highly scalable API for AI image enhancement
When we started our photo editing service - Autoenhance.ai - we considered that our web app was the best way for users to enhance their images and receive an instant AI enhancement. Our users interact with multiple services and websites every day. We didn’t want to add to their list; instead, we tried to integrate Autoenhance.ai into existing services utilised by our users. We had many conversations with potential clients in those early stages, and “Do you have an API?” was the question many people asked. We then had to ask ourselves: “Why don't we have an API?”
We’d built a successful internal API, but it wasn’t a RESTful API by definition. Initially, we gave our users access to this API, but there were many flaws, such as security, and the layout of the API was not intuitive. It required a 30-minute walk-through to understand it.
In March, James Campbell joined Autoenhance.ai as CTO. First, I gave him a walkthrough of our API and straight away, he called me out, saying that the API isn’t simple. He immediately called the team and said, “ We’re going to engineer a new Autoenhance.ai API”.
We started with security. AWS is our cloud provider, which has an excellent platform called API gateway to provision API keys for clients and maps pricing plans. This visibility allows us to lock the whole system down and monitor individual users to ensure we provide the right AI resources.
Secondly, we focussed on scalability. We used Sagemaker (a platform as a service) for our AI endpoints, but running on GPUs didn’t give us the scalability we needed to make our AI reactionary to API usage. We required smaller CPU instances that could be provisioned at peak usage (afternoons) and scaled-down during low use (at night). Additionally, we wanted to move away from ECS (elastic container service) to something even more scalable - serverless. However, some drawbacks include uploading images to serverless, limited to the maximum storage size of 6MB payload. We overcame this by providing users with a signed S3 endpoint for uploading pictures.
With our new architecture in place, we’ve started to make our endpoints more intuitive. Previously our endpoints were POST /upload, POST /status and POST /getimage, which relates to the user’s actions. However, this is not RESTful. Our new API uses the CRUD format e.g. POST /image to upload the image, GET /image/{imageid} to get the image status, GET /image/{image_id}/enhanced, to view the enhanced image.
Since releasing the new architecture, we’ve provided a consistent average turnaround time of 10 seconds per image and scaled efficiently with zero downtime. We’ve received positive customer feedback, and our visibility across the system assists us in improving the API continually.
The new API was a "great success"
Sign up for our API and follow the steps for integration.
Try our photo editing service to receive the instant enhancement.