Can a transaction avoid inserting duplicate values in my database?

I have the following table named values:

id serial user_id integer store_id integer identifier VARCHAR(255) created timestamp without time zone DEFAULT NOW() 

But my application has inserted following values:

id user_id store_id identifier created
1 1 1 123cdwe 2021-11-11 13:00:00
1 1 1 Ggrseza 2021-11-11 13:00:00

And that values seem wrong. What I suspect is a replication lag between master and slave alongside with an application termination right just after writing. The application is a web one and I suspect that happens whilst user ferfeshed whilst saving.

Would a transaction could solve the problem or this problem should be tackled at application level?