Skip to content

Commit d5ca1cf

Browse files
Merge pull request #80 from SparkPost/feat/sqs-extended-send-uuid-prefix
feat: sqs extended send UUID prefix
2 parents e42bd5f + 3a6f54a commit d5ca1cf

File tree

4 files changed

+2781
-1516
lines changed

4 files changed

+2781
-1516
lines changed

lib/sqs/index.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ module.exports = ({
231231
* too large to fit in sqs, it will write a sqs with a pointer to an s3
232232
* bucket
233233
*
234-
* @param queueName Name of queue
235-
* @param payload body of message
236-
* @param attrs attributes attached to message
237-
* @param s3Bucket bucket name for message storage, if it exceeds limit
238-
* @param prefix bucket path prefix (no slashes)
239-
* @param shards number of bucket shard paths
234+
* @param {string} queueName Name of queue
235+
* @param {string|object} payload body of message
236+
* @param {object} attrs attributes attached to message
237+
* @param {string} s3Bucket bucket name for message storage, if it exceeds limit
238+
* @param {number} shards (deprecated) number of bucket shard paths
239+
* @param {boolean} uuidPrefix use uuid() as S3 path prefix to prevent S3 throttling during high throughput scenarios. When true, ignores 'shards' parameter.
240240
*/
241241
extendedSend: ({
242242
queueName,
@@ -245,7 +245,8 @@ module.exports = ({
245245
s3Bucket,
246246
messageGroupId,
247247
messageDeduplicationId,
248-
shards = 50
248+
shards = 50,
249+
uuidPrefix = false
249250
}) => {
250251
if (!s3Bucket) {
251252
return Promise.reject(new Error('S3 Bucket name required'));
@@ -269,7 +270,13 @@ module.exports = ({
269270
return compress(payload, { level })
270271
.then((payload) => {
271272
if (computeMessageSize(payload, attrs) > MAX_MSG_SIZE) {
272-
key = `/${Math.floor(Math.random() * shards)}/${uuid()}.json.gz`;
273+
// use a random shard as path prefix by default for backwards compatibility,
274+
// however, S3 throttles during high throughput events are more likely.
275+
// `uuidPrefix` allows ultra high throughput by avoiding a fixed number of shards.
276+
const prefix = uuidPrefix
277+
? uuid()
278+
: Math.floor(Math.random() * shards);
279+
key = `/${prefix}/${uuid()}.json.gz`;
273280

274281
return S3.uploadAsync({
275282
Body: payload,

0 commit comments

Comments
 (0)