Hi all,
I'm new to Stellar development and currently building an application in which I grant an asset based on an external event with a unique identifier. I currently do so and keep track of the created transaction in my own database so that I can verify that the asset is granted only once per external event.
The problem I'm trying to solve, however, is making the system not have to rely on the database record of the transaction to avoid duplication. For example, the database can fail; or a network failure might cause the transaction to be posted to Stellar but not verified & recorded in the app; and there can be race conditions of multiple clients trying to post the event at the same time. I'd like for the de-duplication to be enforced at the ledger level rather than in my application logic, using the application database only as a cache.
It would be possible of course to read back every single transaction from the Stellar account before submitting a new one, but this would be tedious and prohibitively time consuming to do on every transaction. What I'd ideally like to do is have a unique identifier that is hashed from the external event ID, and have the Stellar ledger reject the transaction if it's a duplicate. I don't see any functionality like this in the docs, however.
What is the correct strategy here to let the application retry the transaction, but guarantee not to create a duplicate? How is this type of problem more generally solved on the Stellar network?
Thanks!