Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New serverless pattern - dynamodb-lambda-elasticache #1735

Conversation

mansiyd
Copy link
Contributor

@mansiyd mansiyd commented Oct 11, 2023

Issue #1734, if available:

Description of changes:
New serverless pattern submission for implementing CQRS pattern using AWS serverless services

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.


This project contains an event-driven microservices design pattern that is influenced by the [CQRS Pattern](https://microservices.io/patterns/data/cqrs.html).

This pattern will write data into a DDB table and then create a stream from it. Lambda is then used to process the change events in the database and replicate the data in Elasticache for faster reads..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DDB -> change to DynamoDB

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


Once you have run `sam deploy --guided` mode once and saved arguments to a configuration file (samconfig.toml), you can use `sam deploy` in future to use these defaults.

1. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error: Unable to upload artifact OrderPublisher referenced by CodeUri parameter of OrderPublisher resource.
Parameter CodeUri of resource OrderPublisher refers to a file or folder that does not exist /serverless-patterns/dynamodb-lambda-elasticache/OrderPublisher

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


## Testing

Invoke the OrderPublisher lambda function with the following payload, which will create the new order in the DynamoDB table. Note the order id received as a response from the Lambda function, which can be used to query the order data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lambda

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

{"cliendId":"123456789","productId":"abc-def-ghi"}
```

Invoke the OrderQueryService lambda function with the following payload. Replace the ```<order-id>``` with the Order Id returned by the previous Lambda function, to view the order details fetched from the Elasticache.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lambda

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

## Cleanup

1. Delete the stack
```bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use sam delete instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,78 @@
# CQRS pattern with Amazon DynamoDB, AWS Lambda and Amazon Elasticache for Redis

This project contains an event-driven microservices design pattern that is influenced by the [CQRS Pattern](https://microservices.io/patterns/data/cqrs.html).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im just dont know how this pattern makes it faster than a normal read to DynamoDB. Have you tested that? DynamoDB has a single milisecond performance and doesnt need to be behind a VPC to work. It would be great to get this pattern backed by some data before creating it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern focuses on microservices architecture use-cases where each microservice owns one or more sub-domains and a database dedicated to the domain. Due to this architecture pattern, it's no longer starightforward to implement queries and join data from multiple services. For example, for ordering service, each service is responsible for different writes like create-order service. And to "get order order details" we might need to join from multiple tables like order, payment, customer details etc. Since both reading and writing have different approaches, we can employ different strategies for each operation. CQRS (Command and Query Responsibility Segregation) uses “separation of concern” principle to separate the read database from the write database.

Commands perform mutation operations such as “create order” or “update order”. Queries perform ready-only operations such as “Get order details”. By this isolation, we can design purpose-built database based on the usage requirement. With the CQRS pattern, we could implement multiple denormalised views that make the application scalable and performant by simplifying the command query models because of its separation of concern principle.

In this pattern we are using DynamoDB for the high-performant writes and Elasticache for building materialised views for the application reads

@mansiyd mansiyd force-pushed the mansiyd-feature-dynamodb-lambda-elasticache branch from 87f96a6 to f3c65cf Compare October 17, 2023 06:38
@mansiyd
Copy link
Contributor Author

mansiyd commented Oct 17, 2023

all review comments have been addressed

@mavi888
Copy link
Contributor

mavi888 commented Oct 23, 2023

Getting an error when doing sam deploy

Error: Unable to upload artifact target/dynamodb-lambda-elasticache-1.0-SNAPSHOT.jar referenced by CodeUri parameter of OrderPublisher resource.
Parameter CodeUri of resource OrderPublisher refers to a file or folder that does not exist /serverless-patterns/dynamodb-lambda-elasticache/target/dynamodb-lambda-elasticache-1.0-SNAPSHOT.jar
```

@mansiyd
Copy link
Contributor Author

mansiyd commented Oct 23, 2023

@mavi888 just checking if you have performed a Maven build before doing sam deploy? If not, you would have to run the command "mvn clean install" to build the project which will create the jar file in the target folder, which can then be deployed using sam

@mansiyd mansiyd force-pushed the mansiyd-feature-dynamodb-lambda-elasticache branch from f3c65cf to 826f46d Compare October 24, 2023 11:28
@mansiyd
Copy link
Contributor Author

mansiyd commented Oct 31, 2023

@mavi888 could you please provide an ETA for the code review, since its open since 3 weeks and is blocking our other tasks that are dependent on this repo. Thanks

@mansiyd mansiyd requested a review from mavi888 November 1, 2023 05:17
* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java and maven should be listed here

@mavi888
Copy link
Contributor

mavi888 commented Nov 6, 2023

Just run the maven clean build and Im getting an error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project dynamodb-lambda-elasticache: Fatal error compiling: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid' -> [Help 1]

Make sure that all the prerequistes are listed, maybe im missing something.

@mansiyd
Copy link
Contributor Author

mansiyd commented Nov 6, 2023

@mavi888 it seems to be an issue with the Java version. the compiler version is 11, as mentioned in the pom. can we have a working session, so we can resolve all issues in a single go?

@mansiyd mansiyd force-pushed the mansiyd-feature-dynamodb-lambda-elasticache branch from 826f46d to ed69f63 Compare November 6, 2023 10:12
@mansiyd mansiyd force-pushed the mansiyd-feature-dynamodb-lambda-elasticache branch from ed69f63 to d377058 Compare November 6, 2023 10:16
@mansiyd mansiyd requested a review from mavi888 November 7, 2023 05:32
@jbesw
Copy link
Contributor

jbesw commented Nov 9, 2023

Unfortunately we don't have the resources to help troubleshoot this. Patterns should be simple, low-code, IaC frameworks to connect services. I would recommend submitting this as a pattern instead if you are able to fix the issues.

@jbesw jbesw closed this Nov 9, 2023
@mansiyd
Copy link
Contributor Author

mansiyd commented Nov 10, 2023

Closing this PR, as we have published as a repo instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants