top of page

Event sourcing microserices with Azure

  • Writer: Anand Nerurkar
    Anand Nerurkar
  • 3 hours ago
  • 3 min read

Event Sourcing + CQRS – Azure BFSI Microservices

1. Overview of Event Sourcing + CQRS

  • Event Sourcing: Persist domain events (LoanApproved, SIPExecuted, WalletCredited) in Event Hub instead of final state.

  • CQRS (Command Query Responsibility Segregation):

    • Command side: Writes events to Event Hub.

    • Query side: Projections created in Cosmos DB/Azure SQL for fast reads and dashboards.

  • Analytics & Compliance: Long-term event storage in Azure Data Lake (WORM) → analysis via Synapse Analytics.

Use Case 1: Loan Microservices (Event Sourcing + CQRS)

Text Diagram

[Loan Application Command API]

|

v

Azure API Management (APIM)

|

v

Loan Service (Command) → Event Hub (LoanEvents)

|

+----> Cosmos DB (Read Model – Loan Status)

+----> Azure SQL (Projections – Disbursement)

+----> Azure Data Lake (Immutable Audit – RBI)

|

v

Synapse Analytics → Power BI (Compliance Dashboard)

Step-by-Step Flow

  1. Command Side (Write Events)

    • Loan Service validates application → emits LoanApplied event to Event Hub.

    • Subsequent events: KYCVerified, CreditChecked, FraudCheckPassed, LoanApproved.

  2. Event Storage

    • Event Hub serves as immutable event log (10-year retention for RBI compliance).

  3. Projection (Query Side)

    • Azure Functions/Stream Analytics consume Event Hub events:

      • Update Cosmos DB: Loan status, approval progress (for mobile app).

      • Update Azure SQL: Payment/disbursement projections for finance team.

  4. Analytics

    • Event Hub archives → Azure Data Lake (WORM) → Synapse Analytics for reporting (loan volumes, NPA analysis).

  5. Multi-Tenancy

    • Separate Event Hub namespaces or partitions per bank (ICICI, HDFC) for isolation.

Use Case 2: Mutual Fund Microservices (Event Sourcing + CQRS)

Text Diagram

[SIP/Redemption Command API]

|

v

APIM (Tenant-aware JWT)

|

v

SIP Service / Redemption Service → Event Hub (MFEvents)

|

+----> Cosmos DB (Portfolio Read Model)

+----> PostgreSQL (NAV Projections)

+----> Azure Data Lake (SEBI Audit Logs)

|

v

Synapse Analytics → Power BI (Investor Reports)


Step-by-Step Flow

  1. Command Side (Write)

    • SIP Service emits SIPRegistered, SIPExecuted events to Event Hub.

    • Redemption Service emits RedemptionRequested, RedemptionSettled events.

  2. Projection Side (Read)

    • Cosmos DB stores portfolio projections (per investor, per scheme).

    • PostgreSQL (or Azure SQL) stores NAV snapshots for daily reporting.

  3. Analytics

    • Event Hub → Data Lake (SEBI requires 7-year retention of NAV/SIP logs).

    • Synapse + Power BI dashboards for investor insights, compliance reports.

  4. Tenant Isolation

    • API Management injects tenant ID into event metadata → partitions projections in Cosmos DB.

Use Case 3: Digital Wallet Microservices (Event Sourcing + CQRS)

Text Diagram

[Wallet Transaction Command API]

|

v

Azure API Management

|

v

Transaction Service (Command) → Event Hub (WalletEvents)

|

+----> Cosmos DB (Real-time Balance Projection)

+----> Azure SQL (Ledger for Reconciliation)

+----> Azure Data Lake (RBI Audit Trail)

|

v

Synapse Analytics → Power BI (Fraud/Usage Reports)


Step-by-Step Flow

  1. Command Side

    • Wallet top-up, payment, transfer events emitted (WalletCredited, WalletDebited).

  2. Event Storage

    • Event Hub captures immutable transaction events.

  3. Projections (Query Side)

    • Cosmos DB: Near real-time balance queries for mobile app.

    • Azure SQL: Ledger-style reconciliation for finance back-office.

  4. Fraud Detection

    • Event Hub events streamed to Azure ML (Kafka endpoint) for anomaly detection.

  5. Compliance

    • Immutable logs archived to Data Lake (RBI requires 10-year retention).

Azure Services Used (Common Across All)

  • Event Hub: Kafka-compatible event store for write side

  • Cosmos DB: Low-latency projections (read side)

  • Azure SQL/PostgreSQL: Aggregated projections (finance, compliance)

  • Azure Data Lake: Long-term immutable storage (WORM lock for RBI/SEBI)

  • Synapse Analytics: BI/reporting (loan portfolio, SIP activity, wallet fraud patterns)

  • Power BI: Dashboards for CXOs, auditors, regulators

  • Azure Functions/Stream Analytics: Real-time projection updates

Multi-Tenant Architecture (SaaS BFSI)

  • Event Hub Namespaces: One per tenant (ICICI, HDFC) OR partition keys per tenant

  • Cosmos DB: Partition by tenantId for isolated projections

  • API Management: JWT token includes tenantId, propagated to events

Text Diagram (Combined Multi-Tenant CQRS Flow)

[API Management (Tenant-aware)] --> [Event Hub (Partitioned by Tenant)]

| |

|----> [Cosmos DB (Per-tenant projections for Mobile/Web)]

|----> [Azure SQL/PostgreSQL (Finance & Compliance projections)]

|----> [Azure Data Lake (Immutable WORM logs)]

|

v

[Synapse Analytics + Power BI → Regulatory Dashboards (RBI/SEBI)]

 
 
 

Recent Posts

See All
Microservices 3

Section 2 – BFSI Use Case Architectures (Azure Cloud) Use Case 1: Loan Microservices 1. High-Level Architecture Flow [Customer App/Web] ...

 
 
 

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
  • Facebook
  • Twitter
  • LinkedIn

©2024 by AeeroTech. Proudly created with Wix.com

bottom of page