GoSalesStream is a project that simulates E-commerce transactions and provides real-time analytics based on these transactions. The project is written in Golang, uses gRPC for communication, and stores data in a CockroachDB database.
- Go
- CockroachDB
- A SQL client (e.g., DBeaver)
- Postman
- Setup DB
then
cockroach start --insecure --store=node1 --listen-addr=localhost:26260 --http-addr=localhost:8089 --join=localhost:26260 --background
cockroach init --insecure --host=localhost:26260
- Create database & seed data
- Open the
/db_setup.sql
file, copy the SQL commands. - Paste and execute the SQL commands in your SQL client to set up the database schema. type (option + x) to run all commands
-
Clone the repository:
git clone https://github.com/Mosaibah/GoSalesStream
-
Navigate into the project directory:
cd GoSalesStream
-
Build the project
task build
-
Run transaction service
task run-transaction
-
Run analytics service
open new terminaltask run-analytics
-
Open Postman.
-
Add a gRPC request for the transactions service. Import the protobuf file from
GoSalesStream/packages/proto/transaction/v1/transaction.proto
. -
Add another gRPC request for the analytics service. Import the protobuf file from
GoSalesStream/packages/proto/analytics/v1/analytics.proto
.
Now, you can simulate transactions and retrieve real-time analytics using the imported gRPC requests in Postman.
{
"transaction_id": 2
}
{
"transaction":
{
"customer_id": 1,
"product_id": 2,
"price": 122,
"quantity": 45
}
}
{
"product_id": 2
}
-
E-commerce Transactions Microservice: Build a microservice in Golang that simulates E-commerce transactions. Each transaction should have a unique id, a timestamp, a customer id, a -product id, a quantity, and a total price.
-
gRPC Service Definitions: Use Protobuf to define gRPC services for creating, retrieving, and streaming transactions. CreateTransaction service will allow you to simulate a new transaction. GetTransaction service will return a specific transaction based on its id. StreamTransactions service should stream transactions in real-time.
-
CockroachDB Integration: Store transactions in CockroachDB. There should be a function for writing transactions to the database, as well as for reading transactions.
-
Temporal Workflows: Implement a Temporal workflow for processing each transaction. The workflow should handle retries in case of failures during the transaction process.
-
Analytics Microservice: Implement another microservice in Golang that calculates and provides real-time analytics based on transactions. This microservice should expose gRPC services for streaming the current total sales, sales by product, and the top 5 customers.
-
Unit Tests: Write unit tests for both microservices. The tests should cover gRPC handlers, Temporal workflows, and database interactions.
-
Docker and Kubernetes: Both microservices should be containerized using Docker and deployed on a Kubernetes cluster.
-
CreateTransaction: Ability to simulate a new transaction.
-
GetTransaction: Ability to fetch a specific transaction based on its id.
-
StreamTransactions: Ability to stream transactions in real-time.
-
GetTotalSales: Ability to get the current total sales.
-
GetSalesByProduct: Ability to get the current sales by product.
-
GetTopCustomers: Ability to get the top 5 customers based on sales.