A practical solution will be to insert the status of each image into a table indexed with the unique identifier of an image like its hash value or file path: Image hash Competed at Matched image path SHA256: b4337bc45a8f... 2018-02-09T15:15:11+05:30 /celeb/7112.jpg SHA256:550cd6e1e8702... 2018-02-09T15:17:24+05:30 /celeb/3529.jpg You can find the total number of successful matches by counting rows in this table. Additionally, this approach allows you to break down the successful matches by date or time. The race conditions are avoided,