Basket Service (v1.0.0)

Manages the lifecycle of customer shopping baskets in the BookWorm e-commerce system

Overview

The Basket Service is a domain-centric microservice within our bounded context that implements a gRPC-based API architecture to manage the transient state of customer shopping carts. This service encapsulates the complete lifecycle of a basket aggregate, from creation through modification to eventual checkout processing.

As a core part of our Domain-Driven Design implementation, the Basket Service maintains its own dedicated Redis persistence store, ensuring proper encapsulation of the basket domain model. It serves as the system of record for the shopping intent of customers before this intent is transformed into an order through domain events.

Key Responsibilities

  • Basket Lifecycle Management: Creation, modification, and deletion of shopping baskets
  • Item Management: Adding, updating, and removing items with quantity validation
  • Checkout Orchestration: Coordinating the transition from basket to order
  • State Persistence: Maintaining basket state in Redis with configurable TTL
  • Event Publishing: Emitting domain events for basket state changes

Component Diagram

Loading graph...

Core Features

FeatureDescriptionEvent Published
Get BasketRetrieves the current basket for an authenticated user, including all items and their quantities.-
Add Item to BasketAllows customers to add items to their basket, with validation ensuring quantities are greater than zero.BasketItemAddedEvent
Remove Item from BasketEnables customers to remove items from their basket, maintaining data consistency.BasketItemRemovedEvent
Update Item QuantitySupports customers in updating the quantity of items in their basket, with built-in validation.BasketItemQuantityUpdatedEvent
Clear BasketRemoves all items from the basket at once.BasketClearedEvent
Delete BasketPermanently removes the basket from the system.BasketDeletedCompletedEvent

Architecture diagram

Messages for this service

Sends messages (3)

Quickly find the message you need by searching for the name, type, or summary.
NameVersionTypeSummary
Basket Deleted Complete
v1.0.0eventRepresents a domain event that is published when reverse basket is completed
Deleted Basket Fail
v1.0.0eventRepresents a failed basket deletion event in the system
List Books (gRPC)
v1.0.0queryList all books via gRPC

Receives messages (6)

Quickly find the message you need by searching for the name, type, or summary.
NameVersionTypeSummary
Update Basket
v1.0.0commandUpdate a basket
Delete Basket
v1.0.0commandDelete a basket by its unique identifier
Create Basket
v1.0.0commandCreate a new basket for a user
Order Placed
v1.0.0eventReceive a message when an order is placed

Key Concepts

Infrastructure

The Basket Service is deployed as a containerized application within the BookWorm ecosystem, leveraging cloud-native technologies for scalability and resilience.

Loading graph...

Performance Optimizations

  • Connection Pooling: Redis connection multiplexing
  • Caching Strategy: L1 in-memory cache with L2 Redis cache
  • Batch Operations: Bulk item updates in single transactions
  • Async/Await: Non-blocking I/O throughout the stack

Security Considerations

  • Authentication: JWT bearer tokens validated on each request
  • Authorization: Customer can only access their own basket
  • Input Validation: All inputs sanitized and validated
  • Rate Limiting: Per-customer request throttling
  • Data Encryption: TLS for transit, optional Redis encryption at rest