Generate unique code (for ex. discount voucher code) to provide in an offer - batch campaign
We have got a requirement to send a unique voucher code inside an email for a specific as part of batch outbound campaign. The voucher code should be a fixed-length code (with alphanumeric and special characters only) and unique per customer and should only be used once, so let's say if a code "xYz12sD" has been generated and sent once, it should never be generated again.
We have 2 proposed mechanism:
1) Codes will be generated by a 3rd party solution and sent to Pega in a file every 'x' day and we have to maintain the logic of using it once etc as well as integration with the source.
2) Generate codes in Pega, this will eliminate dependency/integration with another solution.
The question is if we want to go with option 2, how to generate such code inside Pega? And is it advisable to do it in Pega?
Thank you very much for sharing your idea. I assume you are suggesting to use "pxGeneratePassword" Activity/API??
It might be helpful, but the question arises: whether it always generates a unique value? And I am not sure how good it will be when comes to performance i.e. using on the fly while running an outbound campaign.
If yes, you can do it internally in Pega. Generate the GUID on the fly i.e. in strategy execution and extend the Fact table and store the GUID in your newly created voucher_code column. That would work because no two GUID can be identical, which means every pySubjectID will get its unique code, and the output will be persisted in Interaction History.
However, if you just generate a short random string on the fly, as per your example be it "xYz12sD", the uniqueness of the string is not guaranteed. There's a possibility that some other customer may get the same voucher code, unlikely but possible. That would push you to first write every on-the-fly generated voucher code to a table in run-time and then query it to make sure that same voucher code is not used before. You will always need to query this new (VoucherCode) table to verify the uniqueness of your voucher code string. Apart from performance concerns, this approach brings new challenges. Given the fact that outbound campaign runs in a multi-threaded fashion, there's still a slim chance that e.g. thread-1 and thread-5 can get the same voucher code simultaneously and when these two separate threads query the VoucherCode table, they would both think that code generated is unique since it's not written/committed there yet; they will both send the same voucher to two different customers. You can always improve your custom "give me a short random string" function by appending few other identifiers to it, be it milliseconds and/or node_id. But you will eventually find yourself writing a new GUID function.
Briefly, I would either proceed with a GUID generation in run-time at strategy level or focus on your option #1 i.e. where unique codes are generated in batch, offline. So that their uniqueness will be guaranteed in advance.