diff --git a/bin/stacks/lambda-stack.ts b/bin/stacks/lambda-stack.ts index e87633e8..6df2c4cf 100644 --- a/bin/stacks/lambda-stack.ts +++ b/bin/stacks/lambda-stack.ts @@ -53,6 +53,7 @@ export class LambdaStack extends cdk.NestedStack { const { provisionedConcurrency, kmsKey, tableCapacityConfig, indexCapacityConfig, chatbotSNSArn } = props const lambdaName = `${SERVICE_NAME}Lambda` + const orderNotificationProvisionedConcurrency = 10 const lambdaRole = new aws_iam.Role(this, `${lambdaName}-LambdaRole`, { assumedBy: new aws_iam.ServicePrincipal('lambda.amazonaws.com'), @@ -142,6 +143,7 @@ export class LambdaStack extends cdk.NestedStack { runtime: aws_lambda.Runtime.NODEJS_18_X, entry: path.join(__dirname, '../../lib/handlers/order-notification/index.ts'), handler: 'orderNotificationHandler', + retryAttempts: 0, memorySize: 512, timeout: Duration.seconds(29), bundling: { @@ -163,8 +165,8 @@ export class LambdaStack extends cdk.NestedStack { const notificationConfig = { startingPosition: aws_lambda.StartingPosition.TRIM_HORIZON, - batchSize: 1, - retryAttempts: 1, + batchSize: 10, + retryAttempts: 0, bisectBatchOnError: true, reportBatchItemFailures: true, } @@ -364,7 +366,7 @@ export class LambdaStack extends cdk.NestedStack { this.orderNotificationLambdaAlias = new aws_lambda.Alias(this, `OrderNotificationAlias`, { aliasName: 'live', version: this.orderNotificationLambda.currentVersion, - provisionedConcurrentExecutions: enableProvisionedConcurrency ? provisionedConcurrency : undefined, + provisionedConcurrentExecutions: orderNotificationProvisionedConcurrency, }) if (enableProvisionedConcurrency) { diff --git a/lib/handlers/order-notification/handler.ts b/lib/handlers/order-notification/handler.ts index 7e90c3a7..b12cc5f9 100644 --- a/lib/handlers/order-notification/handler.ts +++ b/lib/handlers/order-notification/handler.ts @@ -10,7 +10,7 @@ import { DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC } from '../constants' import { Unit } from 'aws-embedded-metrics' import { ChainId } from '../../util/chain' -const WEBHOOK_TIMEOUT_MS = 500 +const WEBHOOK_TIMEOUT_MS = 200 export class OrderNotificationHandler extends DynamoStreamLambdaHandler { public async handleRequest(input: { @@ -52,7 +52,9 @@ export class OrderNotificationHandler extends DynamoStreamLambdaHandler[] = registeredEndpoints.map((endpoint) => + // Randomize the order to prevent any filler from having a consistent advantage + const shuffledEndpoints = [...registeredEndpoints].sort(() => Math.random()) + const requests: Promise[] = shuffledEndpoints.map((endpoint) => axios.post( endpoint.url, {