Rating Service (v1.0.0)

Handles the collection, storage, and aggregation of user feedback and ratings for books on the BookWorm platform

Overview

The Rating Service represents a distinct bounded context within the BookWorm ecosystem, responsible for managing user feedback and ratings for books. As a core domain service, it implements Domain-Driven Design principles to maintain a clean separation of concerns while providing critical functionality for the user experience.

Key Responsibilities

  • Feedback Collection: Capturing user ratings, reviews, and sentiment analysis
  • Rating Aggregation: Computing real-time rating metrics and statistics
  • Content Moderation: Validating and filtering review content for quality
  • Event Broadcasting: Publishing domain events for system-wide rating updates
  • Analytics Support: Providing rating trends and insights for business intelligence
  • Fraud Detection: Identifying and preventing rating manipulation

Component Diagram

Loading graph...

Domain Events

The service emits domain events such as FeedbackCreatedEvent and FeedbackDeletedEvent to notify other bounded contexts about changes in the rating domain. These events enable loose coupling between services while maintaining data consistency.

Integration Points

Rating Service integrates with:

  • Catalog Service: Updates book rating information
  • Notification Service: Triggers notifications for review responses

Implementation Details

The service follows the CQRS pattern with separate command and query models, enabling optimized read and write operations. The repository pattern is used for data access, ensuring persistence concerns remain separated from domain logic.

Core Features

FeatureDescription
Add FeedbackAllows users to submit feedback and ratings for books, storing them in the database.
Delete FeedbackSupports the removal of user feedback, updating the book’s rating metrics accordingly.
Get FeedbacksProvides an API endpoint to retrieve feedback for a specific book or user.

Architecture diagram

Technical Architecture

The Rating Service is built on a modern, cloud-native architecture following these key design principles:

Command Query Responsibility Segregation (CQRS)

Loading graph...

The service implements CQRS pattern with:

  • Command Stack: Handles write operations through commands like CreateFeedbackCommand and DeleteFeedbackCommand
  • Query Stack: Manages read operations with queries like ListFeedbackQuery
  • MediatR Pipeline: Processes commands and queries with cross-cutting concerns:
    • Validation behavior
    • Activity tracking for observability
    • Logging behavior

Event-Driven Architecture

Loading graph...

The service publishes domain events that are transformed into integration events for cross-service communication:

  • Domain Events: FeedbackCreatedEvent, FeedbackDeletedEvent
  • Integration Events: FeedbackCreatedIntegrationEvent, FeedbackDeletedIntegrationEvent
  • Event Bus: Implemented with MassTransit for reliable message delivery
  • Inbox/Outbox Pattern: Ensures at-least-once delivery semantics

Infrastructure

This service is built using C# and .NET Core, leveraging Entity Framework Core for data access and Azure Cosmos Database for persistence. The service is containerized using Docker and deployed to Azure Kubernetes Service (AKS) for scalability and reliability.

Loading graph...

Performance Optimizations

  • Read Replicas: Queries directed to read replicas for scalability
  • Caching Strategy: Multi-level caching with Redis for hot data
  • Batch Processing: Aggregated rating updates processed in batches
  • Connection Pooling: Optimized database connections with pooling
  • Async Processing: Non-blocking I/O throughout the stack

Key Metrics

  • Business Metrics

    • Average rating per book
    • Total feedbacks submitted
    • Moderation approval rate
    • User engagement rate
  • Technical Metrics

    • API response times (P50, P95, P99)
    • Cache hit ratio
    • Event processing lag
    • Database query performance
    • Moderation service latency