We are processing items in bulk and want to have multiple jobs running for them without double sending emails or the like. We can't use offset
without potentially having that problem so we are considering splitting UUID ranges.
It should work like:
- Count total amount of items present
- Calculate how many batches we'll need for items present
- Divide UUID range (i.e. 0000... to FFFF...) into potential values
- For 2 batches, this would be (0000... - 7777...F and 8888... - FFFF...)
- Kick off jobs with these given ranges so they can process in parallel without potential collision
Proof of concept code for splitting UUID ranges:
// Load in our dependencies
var BigNumber = require('bignumber.js');
// Define the upper bound of UUIDs
// FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF (without -'s)
var x = new BigNumber('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 16);
// Split our UUID into its parts and rejoin it
var num = 2;
console.log(x.div(num).ceil().mul(num).toString(16));
// Use `BigNumber.max` to prevent overflowing UUIDs