Using S3 pre-signed URLs to enhance image capture performance

Using S3 pre-signed URLs to enhance image capture performance

Not Clapped
Clapped
unlike icon
Liked
Team Shadowfax

With more than 20K ecommerce reverse pickups being handled by Shadowfax each day, there is no need to emphasize on the very important step of quality check at doorstep from customer. As the field executive from Shadowfax reaches the customer and picks up the item for return, a thorough inspection is performed using the rule engine created using the data shared by the merchant whose order item is being returned. In such case, there is a need to extract images taken at doorstep, document and log them for reference in the future and for sharing them back with the merchant. That is where the Image capture reliability is important.

The conventional approach

While uploading the image of the item that the executive has collected, the network request with the image data has to travel from the network the app is in, which is India, to the network the servers are in, which could be anywhere in the world, depending on where they are being hosted. Usual choices companies take (if they are using Amazon Web Services) are the servers in US East or US West, given their cost is lower as compared to other data centers. However, for the image data to travel all the way from India to cross the oceans and land to data centers in US takes time and is unreliable over slow networks of Edge and 2G in India. While Shadowfax launched its Doorstep Quality Check product, this problem started to appear, causing loss of captured image data up to 2–3%.

An approach closer to home for reduced latency

An alternative approach taken by the technical architecture team was to keep a singular file repository in a file server located in Mumbai region in AWS, where all the files will be deposited and the corresponding references to their location in cloud will be sent and stored to the US servers, which would be less expensive (performance wise) than the whole image data. Moving to this approach had measurable and encouraging improvements in performance and reduction in loss of data.

Image for post

However, this architecture had a major flaw, it needed two server calls for a single image upload, one to deposit the image to the Mumbai server, the second to store the image cloud URL in the appropriate business data. This was better than the earlier state, but still had scope for improvement.

While the file routing service was working well, it required a new handling to be introduced whenever a new type of file was required to be uploaded from the app. Also, with increasing scale on our platform as the company is growing, the file service would have to be scaled in the same Mumbai region, leading to added costs for file management. A cheaper, equally efficient solution was the dire need of the hour.

A novel approach for reduced latency and low costs

After some research and community scouting, a new solution emerged. Some libraries that offer direct integration with AWS S3 cloud storage service allow pre-signed URLs to be generated. Back-end stack in Shadowfax is built on Django, which has a very useful library called ‘boto’, which helps in direct integration with S3 service in AWS. The pre-signed URLs can be used from anywhere to send a file using a simple form-post call without any authentication. This is possible within a predefined expiration time limit set during the creation of the URL. In this approach, the server gives this URL to the field executive app for each order, when the image is captured in the app it is sent directly to the AWS Mumbai region S3 buckets, leading to reduced latency of hopping an application server located in Mumbai. While this is happening, the app also makes a call to the application server with any other data that was needed to be sent for performing the action.

Image for post

The above solution is supported by AWS Lambda, which sets up callbacks for events happening in the S3 services being used in the account, including an S3 file creation. The Lambda service sends the data regarding the file that was just created in the S3 bucket, which the application server can receive in the callback with the file name, its size, the buckets it was added in and any other information that is relevant, which can be used to update the correct business data with the uploaded file URL. Although this solution also requires two server calls from the app, both are being made to two different servers, which the app can do parallelly to avoid hiccups in user experience. Also, the file server that routed these files to S3 in the architecture mentioned earlier can now be dropped, which leads to drop in cost (Mumbai region AWS services are more expensive than other regions).

AWS Lambda also allows additional data to be processed and sent back to the application server upon file upload from the app. You can skip the call to your application server to update remaining metadata of the file (like what it was for or some other data like reason for return of the item) by passing that data in the post call to the AWS servers. That data will then be sent in the callback to the application server, making sure all required data is available eventually. Even though this sounds like a more optimised solution, there is a caveat in it of this all being asynchronous. Despite the fact that AWS services are fast and highly reliable (so far, their callback latency is always under one second from the time of upload), there still is some scope of delays. So, the system needs to be architected in a way, along with the user experience, so that this delay is not noticeable or does not impact the purpose it was allowed for.

About Shadowfax

Shadowfax is India’s largest crowdsourced delivery platform with presence in 70+ cities across India and 7000+ daily active delivery personnel. Shadowfax’s unique app enables delivery of food, grocery, pharmacy and e-commerce for businesses and helps them create customer delight using technology. With relentless focus on engineering pleasant experiences for the customers, Shadowfax envisions to become the most desirable and trustworthy delivery platform for customers.

Relevant articles

Shadowfax stories, delivered fresh

plane arrow
Thank you! You have subscribed successfully!
Oops! Something went wrong while submitting the form.
newslatte1newslatter-bg-2.png

Become our
Client

right arrow black
Take on our
Franchise
right arrow black
Cookie Consent

We use cookies on our website for analytics and marketing purposes which helps us to improve the site functionality and user experience. By continuing to use this site, you agree to our use of cookie policy.

Unable to find what you were looking for?

Get in Touch

Company Information

Shadowfax is India's Fastest Growing End-to-End Logistics provider that provides e-commerce, hyper-local, on-demand delivery solutions for businesses for seamless business operations and dynamic growth.

Office Address

1st floor, Appek Building, 93/A,4th B Cross Rd,
5th Block, Koramangala, Bengaluru, Karnataka - 560095