Building an Event-Driven E-Commerce System on AWS for QuantaSneaks 900

Long, long ago, way back in 2025, QuantaSneaks 900πŸ‘Ÿ was launched. At that time, the architect decided to use an event-driven system for the shopping functionality.

In this blog post, we will understand how event-driven systems can be used to create an e-commerce application and implement it with the help of AWS CDK.

Requirements for QuantaSneaks e-commerce.

We want to create an e-commerce application where QuantaSneaks products can be listed, and customers can buy and order them.

Payments are processed with Stripe. Once a payment starts, the product is reserved, so if only one item is left, others can’t pay for it at the same time, similar to a movie booking site. Also, order data is recorded for analytics purposes.
After successful payment at Stripe’s end, the order moves to the shipping service. A notification is sent to the user, and analytics are recorded.

And all of this should be done in an event-driven way using AWS EventBridge for choreography.

Choreography πŸ’ƒ vs Orchestration 🎼

In the choreography way of doing things, services (these days, AI agents) act based on what other services are doing. It’s analogous to how a dance is choreographed, where the action or reaction of one entity depends on another.
In AWS, we use EventBridge to as a medium of communication (using events) for choreography.

In orchestration, there is a single entity that is controlling the workflow. It calls other entities or services, and those services return their responses to the central coordinator, which manages the workflow. It’s analogous to an orchestra where one person orchestrates the workflow of the orchestra.

Quantasneaks 900 Event-Driven Architecture

When an order is placed, the createOrder lambda function is triggered and creates a unique orderId. This orderId is stored in DynamoDB and will act as a common thread (unique token or identifier) for subsequent events. Also, an event with type OrderCreated (with id and necessary details) is posted to EventBridge.

orderId is returned to the frontend and used to poll DynamoDB to get the status of the order. For now, status can be either reserving inventory or initiating payment.

On the AWS side, the OrderCreated event is fanned out to the inventory service, payment processor service, and analytics service. The inventory service blocks the item in inventory. The payment processor service creates a Stripe session URL and stores it in DynamoDB for that particular orderId.

While polling, when the frontend finds the URL, it redirects to that Stripe payment page, and the user completes the payment.

Now Stripe can either post payment information to a webhook (lambda) or to the partner Eventbrite bridge for Stripe. Either way, a PaymentSucceeded event is created in EventBridge and fanned out to the notification service, shipping service, and the analytics service.

And that’s how choregraphy based event driven pattern can be used for an e-commerce workflow.

Let’s BuildπŸš€

I have created infrastructure as code using AWS CDK, which means you can play with the project in minutes.

First of all, clone the repository from here: https://github.com/TrickSumo/Serverless-Introduction/tree/main/eventdriven

Then create a Stripe account (a dev account will do the work) and get the Stripe key and Stripe webhook key. Then export it in the terminal:

export STRIPE_SECRET_KEY=sk_test_...
export STRIPE_WEBHOOK_SECRET=whsec_...

After that, just run CDK and deploy. As simple as that!

npm install
npx cdk bootstrap          # one-time per account/region
npx cdk deploy

Use the Stripe CLI to register the webhook URL that you got after successful deployment:

stripe listen --forward-to <WebhookUrl>
stripe trigger checkout.session.completed

To test, subscribe to the SNS topic:

aws sns subscribe --topic-arn <NotificationTopicArn> --protocol email --notification-endpoint [email protected]
# then confirm the email

Time to testπŸŽ‰

# Create an order (prices are in cents)
curl -X POST "<ApiUrl>orders" \
  -H "content-type: application/json" \
  -d '{"currency":"usd","customerEmail":"[email protected]","items":[{"name":"T-Shirt","price":2500,"qty":2}]}'
# β†’ { "orderId": "...", "status": "CREATED" }

# Poll until checkoutUrl appears, then open it to pay
curl "<ApiUrl>orders/<orderId>"

Conclusion

In this post, we walked through the requirements for the QuantaSneaks e-commerce app and discussed why an event-driven approach with EventBridge fits the choreography style.

Do try the AWS CDK, and if you like, feel free to contribute the frontend for the project. Would love the collaboration 😊

Curious how to build an event-driven e-commerce application using orchestration? Check out Building Human-in-the-Loop E-Commerce Workflows with AWS Durable Lambda Functions.

Thanks, and Enjoy Building!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.