Skip to content

Explore Datadog's serverless observability features with this sample app.

License

Notifications You must be signed in to change notification settings

DataDog/serverless-sample-app

Repository files navigation

Serverless Getting Started

Caution

Deploying resources in this repository may incur costs in your AWS or DataDog account. Each runtime specific README contains instructions on deleting all resources, it is recommended you do this when not in use.

This repository contains source code for demonstrating the getting started experience when using native tracing through various AWS serverless technologies. It implements the same architecture in all the available Lambda runtimes, and different IaC tools to provide a getting started experience for where ever you are today.

Architecture Diagram

Implementations

Node Python .NET Java Go Rust
AWS CDK Y Y Y Y Y
AWS SAM Y Y Y Y Y
Terraform Y Y Y Y Y
Serverless Framework Y N Y
SST v2 Y

End to End Tracing Output

Once deployed, the system demonstrates the full end to end observability Datadog provides. Including automatic trace propagation through multiple asynchronous message channels, backend services and demonstrates SpanLinks.

End to end tracing

The application simulates Product, Inventory and Analytics services, inside an eCommerce application. The functionality is managed by three independent teams, the product service, inventory service and analytics service team. Interactions between domains runs through a shared Amazon EventBridge EventBus.

Demo Application

Product Service

The product service is made up of 3 independent services, that interact asynchronously.

  1. The ProductAPI provides CRUD (Create, Read, Update, Delete) API provides the ability to manage product information. On all CUD requests, private events are published onto respective SNS topics for downstream processing. The API has one additional Lambda function reacting to PricingChanged events published by the ProductPricingService.
  2. The ProductPricingService. This service consumers ProductCreated and ProductUpdated events published by the ProductAPI and asynchronously calculates pricing discounts for the product. On calculation, it publishes a PricingChanged event onto another SNS topic which the ProductAPI then consumers to update pricing
  3. The PublicEventPublisher acts as a translation layer between private and public events. It takes the ProductCreated, ProductUpdated and ProductDeleted events and translates them into the respective events for downstream processing.

Inventory Service

The inventory service is made up of 2 independent services, that interact asynchronously.

  1. The InventoryAntiCorruptionLayer acts as an anti-corruption layer. It receives requests from upstream services, ensures they are semantically correct against the expected schema and translates them for further processing inside the InventorySevice. This step also acts as a buffer, to prevent overload from upstream services.
  2. The StockOrderingService takes upstream events and starts a StepFunctions workflow to start the processing of purchasing stock for the product

Analytics Service

The analytics service is made up of a single service that recevies all events from EventBridge and increments a metric inside Datadog depending on the type of event received. The analytics service also demonstrates the use of SpanLinks. SpanLinks are useful when two processes are related but don't have a direct parent-child relationship.

In this scenario, analytics spans would add noise to the end to end trace for the product creation and inventory ordering flow. However, causality is still useful to understand. Span Links provide a link, but still keeps independence in the traces.

Load Tests

The repository also includes load-test configuration using Artillery. You can use this to generate load into the product service, and view the downstream data in Datadog.

NOTE The load test runs for roughly 3 minutes, and will generate load into both your AWS and Datadog accounts. Use with caution to avoid billing. As an alternative, a Postman Collection is available that you can use to run test manually. Or you can use the integration tests documented in the respective languages folder.

To execute the loadtests, first ensure Artillery is installed. You will also need to set the API_ENDPOINT environment variable.

cd loadtest
export API_ENDPOINT=
artillery run loadtest.yml