Skip to content

davidmishnev/L0_task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

L0_task

Order Service Demo

This repository contains a demonstration microservice built in Go that processes order data from a Kafka queue, stores it in PostgreSQL, caches it in memory, and provides a simple web interface to view order details by ID.

Assignment Overview

The task is to develop a demo service with a basic interface that displays order data. This involves creating a small microservice in Go using a database and message queue. The service receives order data from a Kafka queue, saves it to PostgreSQL, and caches it in memory for quick access.

What Needs to Be Done

Deploy Database Locally

  • Create a new database for the service.
  • Set up a user: Create a user and grant rights to the created database.
  • Create tables: Design the structure for storing the received order data, based on the attached data model.

Develop the Service

  • Write a Go application implementing the functions described below.
  • Develop a simple interface to display received data by order ID.
  • Connect and subscribe to the message channel: Set up receiving data from the message broker (Kafka).
  • Save received data to the DB: Upon receiving a new order message, parse it and insert the corresponding record(s) into the database (PostgreSQL).
  • Implement data caching in the service: Store the latest received order data in memory (e.g., in a map) for quick retrieval on request.
  • Restore cache from DB on restart: On service start, populate the cache with current data from the database to continue serving requests without delays.
  • Run an HTTP server to serve data by ID: Implement an HTTP endpoint that returns order data from the cache (JSON API) by order_id. If not in cache, fetch from the DB.
  • Develop a simple web interface — a page (HTML/JS) where you can enter an order ID and get information about it by calling the above HTTP API.

Note: The order data model (fields for order, delivery, payment, and items) is provided in the JSON file below.

Data coming from the queue may be invalid — handle errors (e.g., ignore or log incorrect messages). Ensure that in case of failures (DB error, service crash), data is not lost — use transactions, message acknowledgment from the broker, etc.

After Implementation

Ensure that:

  • The service connects to the message broker (Kafka) and processes messages online (you can write a script-emulator for sending messages).
  • The cache indeed speeds up data retrieval (e.g., on repeated requests for the same ID).
  • The HTTP server returns correct data in JSON format.
  • Example request: GET http://localhost:8081/order/<order_uid> should return JSON with order information.
  • The interface displays data clearly after entering the ID and pressing the button.

Result

Once the service is ready, record a short video of the interface in action and submit it along with the repository link for review via the personal cabinet.

Data Model

{
   "order_uid": "b563feb7b2b84b6test",
   "track_number": "WBILMTESTTRACK",
   "entry": "WBIL",
   "delivery": {
      "name": "Test Testov",
      "phone": "+9720000000",
      "zip": "2639809",
      "city": "Kiryat Mozkin",
      "address": "Ploshad Mira 15",
      "region": "Kraiot",
      "email": "test@gmail.com"
   },
   "payment": {
      "transaction": "b563feb7b2b84b6test",
      "request_id": "",
      "currency": "USD",
      "provider": "wbpay",
      "amount": 1817,
      "payment_dt": 1637907727,
      "bank": "alpha",
      "delivery_cost": 1500,
      "goods_total": 317,
      "custom_fee": 0
   },
   "items": [
      {
         "chrt_id": 9934930,
         "track_number": "WBILMTESTTRACK",
         "price": 453,
         "rid": "ab4219087a764ae0btest",
         "name": "Mascaras",
         "sale": 30,
         "size": "0",
         "total_price": 317,
         "nm_id": 2389212,
         "brand": "Vivienne Sabo",
         "status": 202
      }
   ],
   "locale": "en",
   "internal_signature": "",
   "customer_id": "test",
   "delivery_service": "meest",
   "shardkey": "9",
   "sm_id": 99,
   "date_created": "2021-11-26T06:22:19Z",
   "oof_shard": "1"
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages