Product Service ๐ฆ
The Product Service manages the product catalog, categories, pricing, and inventory in the ShopVerse platform.
It acts as the central source of truth for product-related data and supports both public product browsing and admin product management.
๐ฏ Responsibilitiesโ
The Product Service is responsible for:
- Product and category management
- Pricing and inventory tracking
- SKU generation
- Soft deletion of products
- Publishing product lifecycle events
- Serving product data to Order Service
๐ง Why a Separate Product Service?โ
In an e-commerce system, product data is:
- Read-heavy
- Frequently queried
- Business-critical
Separating it into its own service enables:
- Independent scaling
- Clear ownership of catalog logic
- Safe inventory management
- Isolation from order and payment workflows
๐๏ธ High-Level Architectureโ
๐ Security Modelโ
-
All requests pass through API Gateway
-
Gateway injects:
X-User-EmailX-User-Role
-
Public APIs are accessible without authentication
-
Admin APIs are protected using RBAC
No JWT parsing is done inside Product Service.
๐ฆ Product Lifecycle Flowโ
๐๏ธ Data Modelโ
Product Entityโ
idnamedescriptionpricestockskubrandcategoryIdisActive(soft delete)version(optimistic locking)createdAtupdatedAt
Category Entityโ
idnamedescriptionisActive
๐งฉ Soft Delete Strategyโ
Products are never physically deleted.
isActive = falseโ product hidden- Queries automatically filter inactive records
- Prevents data loss
- Maintains order history integrity
๐ก Kafka Events Publishedโ
| Event Type | Topic | Description |
|---|---|---|
| PRODUCT_CREATED | product-events | New product added |
| PRODUCT_UPDATED | product-events | Product updated |
| PRODUCT_DELETED | product-events | Product deactivated |
| PRODUCT_STOCK_UPDATED | product-events | Inventory change |
Consumers:
- Notification Service
- Analytics Service
- Recommendation Service
๐ Public APIs (Client Access)โ
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/products | List active products |
| GET | /api/products/{id} | Get product by ID |
| GET | /api/categories | List categories |
These endpoints are publicly accessible.
๐ ๏ธ Admin APIsโ
| Method | Endpoint | Role | Description |
|---|---|---|---|
| POST | /api/products | ADMIN | Create product |
| PUT | /api/products/{id} | ADMIN | Update product |
| DELETE | /api/products/{id} | ADMIN | Soft delete product |
| POST | /api/products/bulk | ADMIN | Bulk product creation |
๐ Inventory Managementโ
- Stock updates are transactional
- Order Service validates stock before placing orders
- Stock is reduced only after order confirmation
- Optimistic locking prevents race conditions
โ ๏ธ Failure Scenariosโ
โ Product Not Foundโ
- Returns
404 Not Found
โ Insufficient Stockโ
- Order Service rejects order
- Product stock remains unchanged
โ Concurrent Updatesโ
- Optimistic lock exception
- Client retry required
โ๏ธ Key Componentsโ
ProductControllerโ Product APIsCategoryControllerโ Category APIsProductServiceโ Business logicCategoryServiceโ Category logicProductRepositoryโ JPA repositoryKafkaEventPublisherโ Event publishingGlobalExceptionHandlerโ Standard error responses
๐ Scalability Considerationsโ
- Read-heavy APIs can be cached
- Stateless service โ horizontal scaling
- Database indexed on SKU & category
- Kafka decouples downstream consumers
๐งช Testing Strategyโ
- Unit tests for product logic
- Integration tests for inventory checks
- Negative tests for unauthorized access
- Concurrency tests for stock updates
๐ Summaryโ
The Product Service provides:
- Reliable product catalog management
- Secure admin-only mutations
- Event-driven extensibility
- Inventory consistency guarantees
It is a core domain service that directly impacts user experience and order processing.