delayer-aws

Simplistic cloud-native distributed scheduler, serverlessly built on top of AWS services

View the Project on GitHub trestini/delayer-aws

Use of DynamoDB streams for enqueuer

Context and Problem Statement

The [ADR-0003] states that the main purpose of DynamoDB is not hold historical data and must only be used as state holder while the particular schedule is not ready to be in the delayer queue. However, the state will be changed from NEW to PROCESSED exactly when this schedule is posted in the delayer queue. This proposal aims change this behavior, removing the records that are already in delayer queue instead change it to PROCESSED.

Decision Drivers

Considered Options

Pros and Cons of the Options

Move for a solution based on TTL and Dynamo Streams

Decision Outcome

Chosen option was to move to a solution based on Dynamo Streams. The proposed solution doesn’t use TTL, since according AWS docs, the deletion of a expired record should occurs within 48 hours - which, for this case, is not acceptable.

The solution is based in the fact that records generates events in DynamoDB that can be consumed by lambda functions. In this sense, when a new schedule is deleted, a DELETE event is raised, and the function will schedule it for the proper pointInTime. In other hand, when a schedule is placed within the delayer period (the timeframe that events are waiting in the delayer queue), this function deletes this record which generates another DELETE that will be handled. If the schedule is not in the delayer period, it will be stored until the task-1minute-enqueuer finds it and then deletes the record.

Hey, but why api-schedule-post don’t simply put this in que delayer queue directly?

The short answer is: because each lambda should do 0, 1 or tops 2 data transformation.

Each lambda should be very restrict on what it does. api-schedule-post is the function responsible to handle the POST request from API Gateway. Handle and transform the data and store it somewhere is the “reason to exists” of this function. How this information is processed later, is not it’s concern.

Have in mind that in this stage of development, keep the integrity of the design is more important that this fine performance tunning.

Below, the new roles of the involved lambdas:

Positive Consequences:

Negative consequences: