How do I get the value from firebase so that it's not the same as the value the other user got at one time?

Hello everyone, I’m making an app to sell internet vouchers in my app, but I’m confused how to get the voucher code I saved on Firebase. suppose two or more users buy at the same time so that the voucher code sent from Firebase to the app is not the same as the other users. means one voucher code for one user who successfully paid. how should i start this logic?

After getting a voucher just use save block with empty value so if you find an empty block in firebase it is understood that the code was used

Or save multiple vouchers in fb and if user paid mean get voucher codes as a list and select the first item( which is nonempty)then replace the item with empty block in fb

I’ve done your suggestion, and it worked. but this should set firebase rules to true, so is it safe?