Async API
π Imagine you have an API that allows users to upload CSV files. The problem is that the uploaded file might contain +1 million records π±.
β³ Each uploaded file could take 1-5 minutes to process. If you implement a synchronous REST API that waits for the processing to finish before responding, it will significantly impact the user experience π₯΄. Not to mention the issues caused if they refresh or upload the file again.
π€ So, how can you handle this?
You can implement an async API π.
π What is an async API?
With this approach:
1οΈβ£ The Server Responds Immediately β When a file is uploaded, the server only validates that the file has been received, then quickly responds without fully processing the data at that moment.
2οΈβ£ Process the Data in the Background π οΈThe uploaded data will be added to a queue or handed over to a worker running asynchronously on the server.
3οΈβ£ Provide an Endpoint to Track Progress πUsers can check the processing status via another endpoint, such as whether the file is still being processed, completed, or failed.
π― **The Result?**The system becomes more efficient β‘, the server isn't overloaded π₯οΈ, and users donβt have to wait for a long time β±οΈ.
Async API is the solution for handling heavy tasks while delivering a better user experience π‘.