Skip to content

Conversation

@sergiosixi
Copy link

@sergiosixi sergiosixi commented Apr 24, 2025

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 -d command.

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
  }
}

@alinehaxkar alinehaxkar closed this May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants