{"id":15867164,"url":"https://github.com/pacovk/circuit-breaker-cdktf","last_synced_at":"2025-03-16T02:31:15.935Z","repository":{"id":57892804,"uuid":"526254451","full_name":"PacoVK/circuit-breaker-cdktf","owner":"PacoVK","description":"Circuit-Breaker pattern implementation on AWS using Typescript and CDKTF","archived":false,"fork":false,"pushed_at":"2024-10-29T18:12:24.000Z","size":303,"stargazers_count":1,"open_issues_count":11,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-29T20:18:39.150Z","etag":null,"topics":["aws","cdktf","terraform","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PacoVK.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-18T14:51:56.000Z","updated_at":"2022-11-16T14:15:55.000Z","dependencies_parsed_at":"2023-02-06T13:15:41.092Z","dependency_job_id":"670f3841-2072-4cb4-9260-a7f43208c2bd","html_url":"https://github.com/PacoVK/circuit-breaker-cdktf","commit_stats":{"total_commits":47,"total_committers":3,"mean_commits":"15.666666666666666","dds":"0.21276595744680848","last_synced_commit":"9489e0c3bbd1367c768bb38b893ea37343d38776"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PacoVK%2Fcircuit-breaker-cdktf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PacoVK%2Fcircuit-breaker-cdktf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PacoVK%2Fcircuit-breaker-cdktf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PacoVK%2Fcircuit-breaker-cdktf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PacoVK","download_url":"https://codeload.github.com/PacoVK/circuit-breaker-cdktf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243801675,"owners_count":20350108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","cdktf","terraform","typescript"],"created_at":"2024-10-05T23:41:34.386Z","updated_at":"2025-03-16T02:31:15.437Z","avatar_url":"https://github.com/PacoVK.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# README #\n\n![Application Tests](https://github.com/PacoVK/circuit-breaker-cdktf/actions/workflows/application.test.yml/badge.svg?branch=main)\n![Infrastructure Tests](https://github.com/PacoVK/circuit-breaker-cdktf/actions/workflows/infrastructure.test.yml/badge.svg?branch=main)\n\nThis repo contains a simple reference implementation of a [ciruit-breaker](https://martinfowler.com/bliki/CircuitBreaker.html) in AWS using **Lambda**, **SNS**, and **DynamoDB**.\n\n## Technology\n\n* [Typescript](https://www.typescriptlang.org/)\n* [Cloud Development Kit for Terraform (CDKTF)](https://www.terraform.io/cdktf)\n\n## The problem\nThe problem to solve pops up when you are starting over with Serverless applications that need to integrate with external APIs. \nYou are charged for the Lambda functions consumed resources (memory and cpu) multiplied by time the lambda is actually running.\nGiven your function relies on external APIs that need to be fetched during runtime, latency of the 3rd. party service becomes a crucial part of your \napplications costs.\nGiven a Lambda is running 600ms we would be charged for 600ms. If the API increases the latency or is down and the HTTP requests \nrun into a timeout after 10 seconds we are charged for the entire 10,5s. Especially in a high traffic environment it \nis very relevant to optimize here.\n\n## The solution\n\nBasically a simple circuit-breaker has the following flow:\n\n![Flow](http://www.plantuml.com/plantuml/proxy?cache=no\u0026src=https://raw.githubusercontent.com/PacoVK/circuit-breaker-cdktf/main/docs/flow.iuml)\n\nDesigned in AWS it could look like this:\n\n![Technical view](http://www.plantuml.com/plantuml/proxy?cache=no\u0026src=https://raw.githubusercontent.com/PacoVK/circuit-breaker-cdktf/main/docs/technical_view.iuml)\n\n## How to use\n\nThe application source is under `application` and the infrastructure related stuff is under `infrastructure`.\n\n**Prerequisite:** Run `yarn install` in the projects root\n\n### Run locally - Application\n\n1. Start local environment with `docker compose up -d` this will setup local SNS,SQS,Dynamodb using [Localstack](https://localstack.cloud/).\nAdditionally there is a [webUI for SQS](http://localhost:3999) and a [webUI for DynamoDb](http://localhost:8001) running on localhost for debugging purposes.\n2. `cd application`\n3. Run `yarn test` to run the functions locally\n\nTo bundle the functions for Lambda run `yarn build` \n\n### Deploy\n\n1. Head over into `infrastructure` \n2. Run `yarn build:deploy:all` - this will bundle the Lambda and deploy all components to AWS\n\n### Cleanup\n\n1. Head over into `infrastructure`\n2. Run `yarn destroy:all` - this will **delete** all components \n\n### Infrastructure Unit tests\n\nThe infrastructure is based on [cdktf](https://www.terraform.io/cdktf). \nto run the jest tests use `yarn test` inside the `infrastructure` folder. Although **no** AWS service will actually be deployed,\nyou need to have valid AWS AccessCredentials in order to meet Terraforms requirements. \n\n## References\n\n* [Circuit Breaker - Martin Fowler](https://martinfowler.com/bliki/CircuitBreaker.html)\n* [SQS Admin](https://github.com/PacoVK/sqs-admin)\n* [DynamoDb Admin](https://github.com/aaronshaf/dynamodb-admin)\n* [cdktf](https://www.terraform.io/cdktf)\n* [Localstack](https://localstack.cloud/)\n* Social preview image by [Greg Bullar](https://unsplash.com/photos/Xlz-BS1BP_Q)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacovk%2Fcircuit-breaker-cdktf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpacovk%2Fcircuit-breaker-cdktf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacovk%2Fcircuit-breaker-cdktf/lists"}