So, I have a bunch of calls that are all being generated with a UUID1 throughout the day. At the end of the call the call is processed and some metrics around that call are generated and stored in Rethinkdb/Cassandra.

Each call will generate something that looks like this

[{
   "company": "foo company",
   "campaign": "bar campaign",
   "hash": "",
   "stat": "talk-time",
   "date": 1467356399,
   "value": 176
 },
 {
   "company": "foo company",
   "campaign": "bar campaign",
   "hash": "",
   "stat": "sale",
   "date": 1467356399,
   "value": 1
 },
 {
   "company": "foo company",
   "campaign": "bar campaign",
   "hash": "",
   "stat": "call-back",
   "date": 1467356399,
   "value": 0
 },
 ...
 ]

I need these stats to be unique within the database. My current solution is to take the UUID of the Call that is stored in Postgres and add it to a string that will look something like this for the first stat uuid1_foo-company_bar-campaign_talk-time_1467356399 and hash it using a SHA-512. Currently, I am using that hash as the ID on Rethinkdb to gain uniqueness.

The reason these need to be unique and reproducible is because sometimes we have to go back and reprocess all the calls for a given day and we need to ensure that stats generated the first time they were processed we kept and not duplicated. If they are duplicated all our reporting would be incorrect.

Is there a better way using these tools to generate unique stats for a call that can be reprocessed later without inserting duplicate values?

Also, it seems that Rethink has a max length of 127 for the primary ID where SHA-512's are 128 characters long, hence rethinking this design.

有帮助吗?

解决方案

I see two possibilities for creating a new key:

  1. Generate A UUID5, which is based on the SHA-1 hash of a namespace identifier (which is a UUID) and a name (which is a string). Use your original UUID and a unique string combination within your record, or

  2. Generate a SHA512 hash of your entire record, encode it to a base64 representation, and append the resulting 8 characters to the end of your original UUID.

许可以下: CC-BY-SA归因
scroll top