Skip to main content

Product Catalog Service

Overview

The Product Catalog Service manages product and category information for the shopping mall. Product data stored in DocumentDB is synchronized to OpenSearch in real-time through Change Streams.

ItemValue
LanguagePython 3.11
FrameworkFastAPI
DatabaseDocumentDB (MongoDB compatible)
Namespacemall-services
Port8000
Health CheckGET /health

Architecture

API Endpoints

Product API

MethodPathDescription
GET/api/v1/productsGet product list
GET/api/v1/products/{product_id}Get product details
POST/api/v1/productsCreate product
PUT/api/v1/products/{product_id}Update product
DELETE/api/v1/products/{product_id}Delete product
GET/api/v1/categoriesGet category list

Request/Response Examples

Get Product List

Request:

GET /api/v1/products?skip=0&limit=20&category=electronics

Response:

{
"products": [
{
"_id": "prod_001",
"name": "Samsung Galaxy S24",
"description": "Latest smartphone",
"sku": "SGS24-256GB",
"price": 1199000,
"currency": "KRW",
"category_id": "electronics",
"images": ["https://cdn.example.com/products/s24.jpg"],
"attributes": {
"color": "Black",
"storage": "256GB"
},
"inventory_count": 150,
"is_active": true,
"created_at": "2024-01-15T10:00:00Z",
"updated_at": "2024-01-15T10:00:00Z"
}
],
"skip": 0,
"limit": 20
}

Create Product

Request:

POST /api/v1/products
Content-Type: application/json

{
"name": "Nike Air Max",
"description": "Comfortable running shoes",
"sku": "NIKE-AM-42",
"price": 189000,
"currency": "KRW",
"category_id": "fashion",
"images": ["https://cdn.example.com/products/airmax.jpg"],
"attributes": {
"size": "270",
"color": "White"
},
"inventory_count": 50,
"is_active": true
}

Response (201 Created):

{
"_id": "prod_002",
"name": "Nike Air Max",
"description": "Comfortable running shoes",
"sku": "NIKE-AM-42",
"price": 189000,
"currency": "KRW",
"category_id": "fashion",
"images": ["https://cdn.example.com/products/airmax.jpg"],
"attributes": {
"size": "270",
"color": "White"
},
"inventory_count": 50,
"is_active": true,
"created_at": "2024-01-15T11:00:00Z",
"updated_at": "2024-01-15T11:00:00Z"
}

Data Models

Product

class Product(BaseModel):
id: str = Field(alias="_id")
name: str
description: Optional[str] = None
sku: str
price: float
currency: str = "USD"
category_id: Optional[str] = None
images: list[str] = []
attributes: dict = {}
inventory_count: int = 0
is_active: bool = True
created_at: datetime
updated_at: datetime

Category

class Category(BaseModel):
id: str = Field(alias="_id")
name: str
description: Optional[str] = None
parent_id: Optional[str] = None
created_at: datetime

Categories (10 Korean Categories)

IDNameDescription
electronicsElectronicsSmartphones, laptops, tablets
fashionFashionClothing, shoes, accessories
beautyBeautyCosmetics, skincare
homeHome/LivingFurniture, interior
foodFoodFresh food, processed food
sportsSportsSports equipment, outdoor
booksBooksBooks, e-books
toysToysToys, games
babyBaby/KidsBaby products, children's clothing
petsPetsPet food, supplies

Events (Kafka)

Published Topics

TopicEventDescription
products.createdProduct CreatedPublished when a new product is registered
products.updatedProduct UpdatedPublished when product information changes
products.deletedProduct DeletedPublished when a product is deleted

Event Payload Example

{
"event_type": "product.created",
"product_id": "prod_001",
"timestamp": "2024-01-15T10:00:00Z",
"data": {
"name": "Samsung Galaxy S24",
"sku": "SGS24-256GB",
"price": 1199000,
"category_id": "electronics"
}
}

Environment Variables

VariableDescriptionDefault
SERVICE_NAMEService nameproduct-catalog
PORTService port8080
AWS_REGIONAWS regionus-east-1
REGION_ROLERegion role (PRIMARY/SECONDARY)PRIMARY
DB_HOSTDatabase hostlocalhost
DB_PORTDatabase port27017
DB_NAMEDatabase nameproduct_catalog
DB_USERDatabase usermall
DB_PASSWORDDatabase password-
DOCUMENTDB_HOSTDocumentDB hostlocalhost
DOCUMENTDB_PORTDocumentDB port27017
KAFKA_BROKERSKafka broker addresslocalhost:9092
OPENSEARCH_ENDPOINTOpenSearch endpointhttp://localhost:9200
LOG_LEVELLog levelinfo

Service Dependencies

Services It Depends On

  • DocumentDB: Product/category data storage
  • MSK Kafka: Event publishing
  • OpenSearch: Search index (synchronized via Change Stream)

Services That Depend On This

  • Search Service: Product search
  • Order Service: Product information lookup during orders
  • Inventory Service: Inventory quantity updates
  • Recommendation Service: Recommended product lookup