Search code examples
image-processingasynchronoususer-experienceimage-uploadingjobs

Processing uploaded images asynchronously: what to do in the meantime?


I need to accept images uploaded by the users, and do some processing in the background, like generating different size thumbnails, a checksum for the original image, check for duplicates, etc. After that, the user should be able to see his submission.

The problem is that the http response will probably be sent before the processing is finished, so what do I tell to the user?

I can think of 4 options:

  • Put a dumb placeholder for the thumbnails, with a sign that reads 'processing' or something, plus an explanation somewhere. The user will have to press f5 until he sees the image, unless he already trusts the system and knows it's going to work.
  • Put a smart placeholder, something like a javascript animation plus recurring ajax calls that will fetch the thumbnails when they are ready. This is great for the user experience, but might generate some overhead in the server.
  • Do the processing asynchronously to avoid overloading, but block the request until the processing is finished. This one looks like a good choice to deliver the product fast, and iterate later if the server starts getting many upload at the same time.
  • Web sockets?

Are there other options? Which one looks better to you? Are there any pros/cons I'm not seeing?


Solution

  • I would go with "Put a smart placeholder, something like a javascript animation plus recurring ajax calls that will fetch the thumbnails when they are ready. This is great for the user experience, but might generate some overhead in the server."

    You can then refine this further based on analytics. With time you will know how long each image would takes to transform based on factors like image size, server-load etc. You can incorporate this knowledge to optimize your JS scripts that poll for results.

    Don't try to optimize without data points and profiling.