Skip to main content

Health check

Check the health status of the Inventory Service, including database and Redis connectivity.

Response

success
boolean
required
Always true for successful health checks
message
string
required
Status message - always “service is healthy”
data
object
required

Example

curl http://localhost:8080/health
{
  "success": true,
  "message": "service is healthy",
  "data": {
    "status": "ok"
  }
}

Initialize inventory

Create a new inventory record for a product with an initial stock quantity. This operation is idempotent - if inventory already exists for the product, it is not modified.

Body parameters

productId
string
required
Unique identifier for the product
quantity
integer
required
Initial available quantity (must be >= 0)

Response

success
boolean
required
Indicates if the operation succeeded
message
string
required
Operation result message
data
object
required

Example

curl -X POST http://localhost:8080/inventory/init \
  -H "Content-Type: application/json" \
  -d '{
    "productId": "prod_001",
    "quantity": 100
  }'
{
  "success": true,
  "message": "inventory initialized",
  "data": {
    "productId": "prod_001",
    "availableQuantity": 100,
    "reservedQuantity": 0,
    "createdAt": "2026-03-03T10:30:00Z",
    "updatedAt": "2026-03-03T10:30:00Z"
  }
}

Get inventory

Retrieve current stock levels for a specific product.

Path parameters

productId
string
required
Product identifier

Response

success
boolean
required
Indicates if the operation succeeded
message
string
required
Operation result message
data
object
required

Example

curl http://localhost:8080/inventory/prod_001
{
  "success": true,
  "message": "inventory fetched",
  "data": {
    "productId": "prod_001",
    "availableQuantity": 85,
    "reservedQuantity": 15,
    "createdAt": "2026-03-03T10:30:00Z",
    "updatedAt": "2026-03-03T11:45:00Z"
  }
}

Add stock

Increase the available quantity for an existing product. The operation uses row-level locking to ensure thread safety.

Body parameters

productId
string
required
Product identifier
quantity
integer
required
Amount to add to available stock (must be > 0)

Response

success
boolean
required
Indicates if the operation succeeded
message
string
required
Operation result message
data
object
required

Example

curl -X POST http://localhost:8080/inventory/add-stock \
  -H "Content-Type: application/json" \
  -d '{
    "productId": "prod_001",
    "quantity": 50
  }'
{
  "success": true,
  "message": "stock added",
  "data": {
    "productId": "prod_001",
    "availableQuantity": 135,
    "reservedQuantity": 15,
    "createdAt": "2026-03-03T10:30:00Z",
    "updatedAt": "2026-03-03T12:00:00Z"
  }
}

Reserve stock

Reserve inventory for a pending order. Stock is moved from available to reserved, and a reservation record is created with an expiration time. The reservation is also cached in Redis.

Body parameters

productId
string
required
Product identifier
orderId
string
required
Order identifier that owns this reservation
quantity
integer
required
Quantity to reserve (must be > 0)

Response

success
boolean
required
Indicates if the operation succeeded
message
string
required
Operation result message
data
object
required

Example

curl -X POST http://localhost:8080/inventory/reserve \
  -H "Content-Type: application/json" \
  -d '{
    "productId": "prod_001",
    "orderId": "order_123",
    "quantity": 5
  }'
{
  "success": true,
  "message": "stock reserved",
  "data": {
    "reservationId": "550e8400-e29b-41d4-a716-446655440000",
    "productId": "prod_001",
    "orderId": "order_123",
    "quantity": 5,
    "status": "RESERVED",
    "expiresAt": "2026-03-03T12:30:00Z",
    "createdAt": "2026-03-03T12:00:00Z"
  }
}

Release reservation

Release a reservation and return stock to the available pool. Use this when an order is cancelled or fails. The operation checks Redis cache before querying the database for improved performance.

Body parameters

reservationId
string
required
Reservation identifier to release

Response

success
boolean
required
Indicates if the operation succeeded
message
string
required
Operation result message
data
object
required

Example

curl -X POST http://localhost:8080/inventory/release \
  -H "Content-Type: application/json" \
  -d '{
    "reservationId": "550e8400-e29b-41d4-a716-446655440000"
  }'
{
  "success": true,
  "message": "reservation released",
  "data": {
    "reservationId": "550e8400-e29b-41d4-a716-446655440000",
    "productId": "prod_001",
    "orderId": "order_123",
    "quantity": 5,
    "status": "RELEASED",
    "expiresAt": "2026-03-03T12:30:00Z",
    "createdAt": "2026-03-03T12:00:00Z"
  }
}

Deduct reservation

Permanently deduct reserved stock when an order is successfully completed. This moves the reservation to the DEDUCTED state and decrements the reserved quantity without returning it to available stock.

Body parameters

reservationId
string
required
Reservation identifier to deduct

Response

success
boolean
required
Indicates if the operation succeeded
message
string
required
Operation result message
data
object
required

Example

curl -X POST http://localhost:8080/inventory/deduct \
  -H "Content-Type: application/json" \
  -d '{
    "reservationId": "550e8400-e29b-41d4-a716-446655440000"
  }'
{
  "success": true,
  "message": "reservation deducted",
  "data": {
    "reservationId": "550e8400-e29b-41d4-a716-446655440000",
    "productId": "prod_001",
    "orderId": "order_123",
    "quantity": 5,
    "status": "DEDUCTED",
    "expiresAt": "2026-03-03T12:30:00Z",
    "createdAt": "2026-03-03T12:00:00Z"
  }
}

Build docs developers (and LLMs) love