Skip to content
DynatracePublic

About

EasyTrade - new demo microservices based application that allows its users to buy and sell stocks, developed by Demoability Team

Resources

Code of conduct

Contributing

Security policy

Stars

56 stars

Watchers

3 watching

Forks

EasyTrade

A project consisting of many small services that connect to each other.
It is made like a stock broking application - it allows it's users to buy&sell some stocks/instruments.
Of course it is all fake data and the price has a 24 hour cycle...

Architecture diagram

Generated from compose.dev.yaml via make update-graph — do not edit the block below by hand.

flowchart TD
    background-service --> db-adapter
    background-service --> offer-service
    broker-service --> db-adapter
    broker-service --> feature-flag-service
    broker-service --> pricing-service
    broker-service --> user-service
    credit-card-order-service --> background-service
    credit-card-order-service --> db-adapter
    db-adapter --> db
    loadgen --> reverse-proxy
    offer-service --> db-adapter
    offer-service --> feature-flag-service
    offer-service --> user-service
    pricing-service --> db-adapter
    reverse-proxy --> background-service
    reverse-proxy --> broker-service
    reverse-proxy --> credit-card-order-service
    reverse-proxy --> feature-flag-service
    reverse-proxy --> frontend
    reverse-proxy --> offer-service
    reverse-proxy --> pricing-service
    user-service --> db-adapter
    background-service -.-> credit-card-order-service
    background-service -.-> feature-flag-service
    credit-card-order-service -.-> feature-flag-service

    class broker-service dotnet
    class background-service,db-adapter,feature-flag-service,pricing-service,user-service go
    class credit-card-order-service java
    class frontend,loadgen,offer-service node
    class db,reverse-proxy other

    classDef dotnet fill:#d2b4de,stroke:#6c3483,color:#1a1a1a,stroke-width:1px
    classDef go fill:#a9cce3,stroke:#1f618d,color:#1a1a1a,stroke-width:1px
    classDef java fill:#f8b4b4,stroke:#c0392b,color:#1a1a1a,stroke-width:1px
    classDef node fill:#a9dfbf,stroke:#1e8449,color:#1a1a1a,stroke-width:1px
    classDef other fill:#d5d8dc,stroke:#5d6d7e,color:#1a1a1a,stroke-width:1px

    subgraph Legend[Legend: implementation language]
        direction LR
        legend_dotnet["C# / .NET"]:::dotnet
        legend_go["Go"]:::go
        legend_java["Java"]:::java
        legend_node["TypeScript / Node.js"]:::node
        legend_other["Other / config (no language manifest)"]:::other
    end
Loading
  • solid arrow: depends_on in compose
  • dashed arrow: inferred from an environment variable value referencing another service
  • dashed border: no entry in compose.dev.yaml (e.g. Kubernetes-only or build-only service)
  • node color: implementation language, detected from the service's manifest file (see the "Legend" group inside the diagram)

Service list

EasyTrade consists of the following services/components:

Service Proxy port Proxy endpoint
Background service 80 /background-service
Broker service 80 /broker-service
Credit card order service 80 /credit-card-order-service
Db -- ---
Db adapter -- ---
Feature flag service 80 /feature-flag-service
Frontend 80 /
Loadgen -- ---
Offer service 80 /offer-service
Pricing service 80 /pricing-service
Reverse proxy 80 ---
User service 80 /user-service

To learn more about a service's endpoints go to its respective readme. Every service also exposes /livez, /readyz and /version, and several ship a .http request collection next to their readme.

Database

All persistent state lives in a single db service. db-adapter is the only component that holds a database connection - every other service reaches it over gRPC on port 50051 using the shared contracts in src/proto.

The backend is selected by DB_TYPE / DB_URL in .env. MSSQL is the default; Postgres is supported as an alternate backend by swapping which of the two pairs is commented out. Schema and seed scripts for each dialect live in src/db/mssql/ and src/db/postgres/.

Docker compose

To run the easytrade using docker you can use provided compose.yaml. To use it you need to have:

  • Docker with minimal version v20.10.13
    • you can follow this guide to update Docker
    • this guide also covers installing Docker Compose Plugin
  • Docker Compose Plugin
    sudo apt update
    sudo apt install docker-compose-plugin
    • more information in this guide

With this you can run

docker compose up
# or to run in the background
docker compose up -d

You should be able to access the app at localhost:80 or simply localhost.

NOTE: It make take a few minutes for the app to stabilize, you may experience errors in the frontend or see missing data before that happens.

NOTE: Docker Compose V1 which came as a separate binary (docker-compose) will not work with this version. You can check this guide on how to upgrade.

Local development

The root Makefile wraps the compose and Helm commands you need while working on the code. It builds images from local source (compose.dev.yaml) rather than pulling them from the registry.

make help    # list every target
make build            # build all images from local source
make start            # start the whole stack, building anything missing
make stop             # stop the stack and remove its containers
make clean            # ...and also drop volumes and locally built images

Every compose target accepts an optional services= to narrow the scope — a single name, or a quoted space-separated list. Omit it to act on the whole stack:

make build services=pricing-service
make start services="db reverse-proxy background-service"

Two targets act on exactly one service and therefore require services=:

make restart  services=frontend   # recreate the container, no rebuild
make redeploy services=frontend   # rebuild the image, then recreate — use after a code change

The dev stack publishes each service on its own host port, so you can hit a service directly instead of going through nginx:

Service Host port Container port
reverse-proxy 80 80
pricing-service 8083 8080
broker-service 8084 8080
offer-service 8087 8080
user-service 8089 8080
credit-card-order-service 8091 8080
frontend 8092 3000
feature-flag-service 8094 8080
background-service 8095 8080
db-adapter 50051 (gRPC), 8096 (health) 50051, 8080
loadgen 8097 8080
db 1433 (MSSQL), 5432 (Postgres) 1433 / 5432

To run the pre-built registry images through the Makefile instead, use make start-remote.

Kubernetes instructions

To deploy Easytrade in kubernetes you need to have:

  • helm
  • kubectl
  • kubeconfig to access the cluster you want to deploy it on
    • more info on it here

Using the Makefile (release name and namespace both default to easytrade):

# create namespace and deploy easytrade from the published chart
make k8s-install-remote

# ...or from the chart in this repo, e.g. to test local chart changes
make k8s-install

# uninstall easytrade
make k8s-uninstall

Both install targets are idempotent (helm upgrade --install), so re-running one upgrades an existing release. Override the defaults per invocation:

make k8s-install HELM_RELEASE=easytrade-test HELM_NAMESPACE=easytrade-test

The equivalent raw commands:

# create namespace and deploy easytrade
helm install easytrade oci://europe-docker.pkg.dev/dynatrace-demoability/helm/easytrade --create-namespace --namespace easytrade

# uninstall easytrade
helm uninstall easytrade -n easytrade

# delete namespace
kubectl delete namespace easytrade

Where to start

After starting easyTrade application you can:

  • go to the frontend and try it out. Just go to the machines IP address, or "localhost" and you should see the login page. You can either create a new user, or use the existing "james_norton/pass_james_123" user (see below). Remember that in order to buy stocks you need money, so visit the deposit page first.
  • browse a service's API - each service readme documents its endpoints, and several ship a .http request collection you can run straight from your editor.
  • after some time go to dynatrace to configure your application and see what is going on in easyTrade - to have it work you will need an agent on the machine where you started easyTrade :P

EasyTrade users

If you want to use easyTrade, then you will need a user. You can either:

  • use the existing user - he has some preinserted data and new data is being generated from time to time:

    • login: james_norton
    • pass: pass_james_123
  • create a new user - click on "Sign up" on the login page and create a new user.

NOTE: After creating a new user there is no confirmation given, no email sent and you are not redirected... Just go back to login page and try to login. It should work :)

Problem patterns

Currently there are 4 problem patterns supported in easyTrade (the feature flag service exposes 8 flags in total - the remaining ones gate frontend flag management, credit card meltdown, credit card memory leak and credit card validation):

  1. DbNotResponding - after turning it on no new trades can be created as the database will throw an error. This problem pattern is kind of proof on concept that problem patterns work. Running it for around 20 minutes should generate a problem in dynatrace.

  2. ErgoAggregatorSlowdown - after turning it on 2 of the aggregators will start receiving slower responses which will make them stop sending requests after some time. A potential run could take:

    • 15 min - then we will notice a small slowdown (for 150 seconds) followed by 40% lower traffic for 15 minutes on some requests
    • 20 min - then we will notice a small slowdown (for 150 seconds) followed by 40% lower traffic for 30 minutes on some requests
  3. FactoryCrisis - when enabled, the factory won't produce new cards, which will cause background-service's manufacture scheduler not to process credit card orders. This will block the Credit Card Order service.

  4. HighCpuUsage - this problem pattern causes a slowdown of broker-service response time and highly increases CPU usage during that time. If the app is deployed on K8s, a CPU resource limit is also applied by background-service's operator subsystem. This should generate CPU throttling on the pod.

The API identifies each pattern by a snake_case flag id, not by the name used above. Note there is no trailing slash - the router redirects /v1/flags/{id}/ and the redirect drops the request body, so the toggle silently does nothing.

Problem pattern Flag id
DbNotResponding db_not_responding
ErgoAggregatorSlowdown ergo_aggregator_slowdown
FactoryCrisis factory_crisis
HighCpuUsage high_cpu_usage

To turn a pattern on/off send a request similar to the following:

curl -X PUT "http://{IP_ADDRESS}/feature-flag-service/v1/flags/{FLAG_ID}" \
-H  "accept: application/json" \
-d '{"enabled": {VALUE}}'

You can also manage enabled problem patterns via the easyTrade frontend.

NOTE: More information on the feature flag service's parameters available in feature flag service's doc.

EasyTrade on Dynatrace - how to configure

All Dynatrace configuration required for Easytrade should be applied using Monaco. More information on how to deploy it can be found in the monaco directory.

Business events in Dynatrace

EasyTrade application has been developed in order to showcase business events. Usually business events can be created in two ways:

  • directly - using one of Dynatrace SDKs in the code - so for example in Javascript or Java
  • indirectly - configure catch rules for request that are monitored by Dynatrace

If you want to learn more about business events then we suggest looking at the information on our website: Business event capture. There you will find information on how to create events directly (with OpenKit, Javascript, Android and more) and indirectly with capture rules in Dynatrace.

For those interested in creating capturing rules for easyTrade we suggest to have a look at the configuration exported with Monaco in this repository. Have a look at the README

Body types

EasyTrade network traffic is handled by REST requests using mostly JSON payloads. However, some of the services can also handle XML requests. Data types are negotiated based on Accept and Content-Type headers.

XML compatible services

Service Accepted XML MIME types
CreditCardOrderService application/xml
OfferService application/xml; text/xml
PricingService application/xml

Local Dynatrace MCP Server

This repository comes with the local Dynatrace MCP Server pre-configured for VSCode. You can read more about MCP Servers on VSCode. In order to try it out, you need access to the Dynatrace Playground Environment, as well as access to GitHub Copilot.

If everything is setup, please open Copilot Chat in VSCode, switch to Agent mode, and ask questions like

Which environment am I connected to?

Are there any problems with my components on Dynatrace?

Are there any security vulnerabilities for my component?

About

EasyTrade - new demo microservices based application that allows its users to buy and sell stocks, developed by Demoability Team

Resources

Code of conduct

Contributing

Security policy

Stars

56 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages

Sponsor
SponsoredKunjungi sekarang
Promo