Skip to main content

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-Email
    • X-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โ€‹

  • id
  • name
  • description
  • price
  • stock
  • sku
  • brand
  • categoryId
  • isActive (soft delete)
  • version (optimistic locking)
  • createdAt
  • updatedAt

Category Entityโ€‹

  • id
  • name
  • description
  • isActive

๐Ÿงฉ 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 TypeTopicDescription
PRODUCT_CREATEDproduct-eventsNew product added
PRODUCT_UPDATEDproduct-eventsProduct updated
PRODUCT_DELETEDproduct-eventsProduct deactivated
PRODUCT_STOCK_UPDATEDproduct-eventsInventory change

Consumers:

  • Notification Service
  • Analytics Service
  • Recommendation Service

๐ŸŒ Public APIs (Client Access)โ€‹

MethodEndpointDescription
GET/api/productsList active products
GET/api/products/{id}Get product by ID
GET/api/categoriesList categories

These endpoints are publicly accessible.


๐Ÿ› ๏ธ Admin APIsโ€‹

MethodEndpointRoleDescription
POST/api/productsADMINCreate product
PUT/api/products/{id}ADMINUpdate product
DELETE/api/products/{id}ADMINSoft delete product
POST/api/products/bulkADMINBulk 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 APIs
  • CategoryController โ€“ Category APIs
  • ProductService โ€“ Business logic
  • CategoryService โ€“ Category logic
  • ProductRepository โ€“ JPA repository
  • KafkaEventPublisher โ€“ Event publishing
  • GlobalExceptionHandler โ€“ 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.