Code Challenge - Sergio Sixi #475
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Notes
To solve the code challenge, two microservices were implemented using NestJS, Postgres, Kafka with Schema Registry, and Jest. The services were designed following Hexagonal Architecture and Domain-Driven Design, and are ready to support new use cases.
anti-fraud-ms
Handles the incoming Kafka messages from the "transactions.created" topic, and perform the business rule mentioned in the challenge. It emit two events: "transactions.rejected" and "transactions.approved" depending on the validation result.
transactions-ms
Expose a GraphQL API to create new transactions validated with class-validator package and to retrieve all of them just to take a look to the db. The transactions are store in a Postgres database. In order to handle massive request of write and read, the CQRS pattern were implemented using NestJS libraries. Despite this, using a MongoDB database for read operations, along with synchronization events, could have been a better approach.
This microservice emit messages to the "transactions.created" topic after saving a new transaction in the database. It also instance a Kafka consumer to handle the "transactions.rejected" and "transactions.approved" events events in order to update the transaction status.
Setup
The entire project is organized in a monorepo and can be run using the
docker-compose up -dcommand.Testing
In order to test the solution, you can use the graphql apollo local UI. http://localhost:3000/graphql and send this example payload
{ "createTransactionInput": { "accountExternalIdDebit": "0c19d290-b5a1-4c62-9a33-d8e7bc3e4a02", "accountExternalIdCredit": "a3b52c13-787e-4936-b2ef-083d10f7f6b4", "tranferTypeId": 2, "value": 90 } }