I'm building an application that involves significant image processing. We're building it in a distributed manor, with an arbitrary number of rendering machines receiving requests to render images from a RabbitMQ exchange.
Because a request for an image might come in while a rendering is already in process, and because I don't want to have two render servers duplicating work, I created a column in the mySQL images table called is_rendering as a boolean.
When a render server receives a request for render it follows a series of steps that looks like this:
- Select for update the image row
- If is_rendering == true abort render request
- Set is_rendering == true and commit the transaction
- Render the image and store the thumbnail in a globally accessible store
- Set is_rendering == false and return
It definitely works, but I'm worried that these frequent database updates seem a little bit silly. Furthermore I'm considering the edge case where a render server fails in the middle of a rendering and leaves is_rendering == true, preventing that image from ever being rendered. The solution I'm considering to this problem is to change the is_rendering column from a tinyint(1) to a datetime field, and storing the date of locking as the "true" value, and null as the "false" value. A periodic service health check could select all rows with a is_rendering value past a certain time period and release the lock in this case.
Is this a sane approach to this problem, or are there other more elegant approaches I should be considering?