To avoid duplicates you should use epoch time as a unique field in your database. Most of the databases are allowed to enable that for one/many fields.
Check your database manual on how to enable that; then, you will have no duplicate records.