Skip to content

sforsandeep/mkopa

Repository files navigation

SMS Command Subscriber

This service implements the Command Subscriber pattern for SMS delivery service, considering the Outbound HTTP Service architecture specification.

Overview

This service processes SMS delivery commands with builtin idempotency controls and event publishing. It separate external SMS provider integration through API calls and ensures proper message delivery tracking.

The processing flow handles:

  1. SMS command validation and idempotency checking
  2. External SMS provider integration via HTTP API
  3. Command state tracking to prevent duplicate sends
  4. Event publishing for success and failure outcomes

Build and Run

Requirements: .NET 9.0 SDK

# Build the solution
dotnet build

# Run all tests
dotnet test

The test suite includes 12 comprehensive tests covering validation, processing logic, error handling, and idempotency scenarios.

Solution Design

Core Components

SendSmsCommand - Immutable command object containing phone number, message content, and unique command identifier for idempotency tracking.

SmsCommandSubscriber - The main processing logic that orchestrates command validation, idempotency checking, SMS provider communication, and event publishing.

Abstraction Interfaces - Clean abstractions for external dependencies (HTTP client, storage, event publishing) that enable testability without infrastructure dependencies.

Event Models - Event objects published for successful sends (SmsRequestSentEvent) and failures (SmsRequestFailedEvent).

Design Decisions

Idempotency Implementation: Commands are tracked by unique identifier to prevent duplicate SMS sends when the same command is received multiple times. This addresses network retry scenarios and ensures customers don't receive duplicate messages.

Dependency Abstraction: All external services are accessed through interfaces rather than concrete implementations. This design enables comprehensive unit testing with mocked dependencies and supports flexible deployment configurations.

Error Handling Strategy - Exceptions are caught and converted to failure events rather than propagating upward. Commands are marked as processed even during failures to prevent infinite retry loops while maintaining proper event notification.

Structured Logging - Includes contextual logging with command identifiers to support debugging and operational monitoring in production environments.

Testing Approach

The test suite covers multiple scenarios:

  • Command validation with various invalid inputs
  • Successful SMS processing with proper event publishing
  • Idempotency behavior when duplicate commands are received
  • Error handling when external services fail
  • Exception scenarios with proper cleanup and event publishing

All external dependencies are mocked using the Moq framework, ensuring tests run quickly and don't require external infrastructure.

Production Considerations

This service focuses on the Command Subscriber component as specified. In a production environment, additional considerations would include:

Retry Logic - The current service doesn't include sophisticated retry mechanisms for transient failures. Production deployments would benefit from exponential backoff and circuit breaker patterns.

Monitoring and Metrics - While logging is included, production would require additional telemetry for SLA monitoring, provider performance tracking, and business metrics.

Configuration Management - SMS provider endpoints, timeouts, and other configuration would need externalization for different environments.

Rate Limiting - Integration with SMS providers usually requires rate limiting to avoid exceeding API quotas.

Development Process and AI Usage

This solution was developed using Test-Driven Development principles with comprehensive unit test coverage. The implementation prioritizes code clarity, maintainability, and adherence to the specified requirements.

During development, Claude AI was used as a development assistant for architecture guidance and implementation best practices. All design decisions, code structure, and final implementation represent my understanding and approach to solving the specified requirements.

About

MKopa Test

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages