go-transaction-service

module
v0.0.0-...-dd3921f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2024 License: MIT

README

go-transaction-service

It is a proof of concept (PoC) for a service written in Golang using hexagonal architecture.

The idea for the notification implementation (pub/sub pattern) is to use low code, taking advantage of cloud resources.

Additionally, it includes samples of a concurrency pattern (workerpool) and unit testing.

Design

alt text

  • Data Model
---
title: Transaction - Data Model Diagram
---
erDiagram
    CUSTOMER ||--|{ TRANSACTION : has
    CUSTOMER {
        string id PK
        string name
        string username
        string createdAt
    }
    TRANSACTION {
        string userId PK
        string transactionId 
        string origin "e.g. “desktop-web”, “mobile-android”,
“mobile-ios”"
        float amount
        string operationType "credit or debit"
        string createdAt
    }

Initially, this is a representation of a NoSQL data model diagram. This is why there is no explicitly mentioned foreign key in the tables

NoSQL was the choice as a high volume of transactions per user is expected, as it can scale horizontally very well, ensuring stable performance. Since the User ID and transaction ID serve as the partition key with high cardinality, it helps avoid hot partitions.

Build

make build

Run Locally

make local

Deploy - AWS lambda

make package-lambda

make deploy

Usage

Create a transaction
  • Header x-idempotency-key: it helps you retry requests safely without accidentally doing the same thing twice. When making or changing an object, use an idempotency key.
curl --location 'https://{{hostname}}/v1/transactions' \
--header 'x-api-key: ******' \
--header 'x-idempotency-key: 82685d92-49a4-4375-aed2-d0f60dab6692' \
--header 'Content-Type: application/json' \
--data '{
    "amount": 99.9,
    "currency": "dollar",
    "origin": "mobile",
    "user": {
        "id": "abc"
    },
    "operationType": "credit"
}'
Subscribe

It is possible to subscribe to receive all transactions in a specific email.

curl --location 'https://{{hostname}}/v1/transactions/subscribe' \
--header 'x-api-key: ******' \
--header 'Content-Type: application/json' \
--data-raw '{
    "protocol": "email",
    "endpoint": "mauriciozanetti86@gmail.com"
}'
List transactions
curl --location 'https://{{hostname}}/v1/transactions?limit=3&next={{token}}' \
--header 'x-api-key: ******' 

Directories

Path Synopsis
cmd
app
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL