EngineeringSenior DeveloperTechnical Sessions

Session 24: Enterprise Architecture - Tổng Hợp & Case Studies

Mục tiêu: Áp dụng tất cả kiến thức vào các hệ thống thực tế theo từng ngành: eCommerce, Logistics, Finance, Insurance.


1. eCommerce Platform Architecture

┌──────────────────────────────────────────────────────────────────┐
│                    eCommerce Platform                             │
│                                                                   │
│  ┌─────────┐   ┌───────────────────────────────────────────┐    │
│  │ NextJS  │──→│          YARP API Gateway                  │    │
│  │ (SSG +  │   │  Rate limiting, Auth, Load balancing       │    │
│  │  ISR)   │   └──────────┬───────────┬──────────┬─────────┘    │
│  └─────────┘              │           │          │               │
│                     ┌─────▼────┐ ┌────▼─────┐ ┌─▼─────────┐    │
│                     │ Catalog  │ │  Order   │ │ Payment   │    │
│                     │ Service  │ │  Service │ │ Service   │    │
│                     │          │ │          │ │           │    │
│                     │ Cosmos   │ │ SQL +    │ │ SQL +     │    │
│                     │ DB       │ │ Redis    │ │ Vault     │    │
│                     └─────┬────┘ └────┬─────┘ └─────┬─────┘    │
│                           │           │             │            │
│                     ┌─────▼───────────▼─────────────▼────┐      │
│                     │      Azure Service Bus             │      │
│                     └───────┬──────────┬─────────────────┘      │
│                             │          │                         │
│                     ┌───────▼──┐ ┌─────▼──────┐                 │
│                     │Inventory │ │Notification│                 │
│                     │ Service  │ │ Service    │                 │
│                     │          │ │ (Functions)│                 │
│                     └──────────┘ └────────────┘                 │
└──────────────────────────────────────────────────────────────────┘

Key Decisions:
- Next.js SSG/ISR cho product pages (SEO + performance)
- Cosmos DB cho Catalog (flexible schema, global distribution)
- Azure SQL cho Orders (ACID transactions)
- Service Bus cho async communication
- Azure Functions cho Notifications (scale to zero)
- Redis cho cart, session, caching

Technology Mapping

ComponentTechnologyReason
Frontend (public)Next.js (App Router, SSG/ISR)SEO, performance
Frontend (admin)React + ViteInternal, no SEO needed
API GatewayYARP.NET native, flexible
Catalog.NET 9 + Cosmos DBFlexible schema, global
Orders.NET 9 + Azure SQL + EF CoreACID, complex queries
Payment.NET 9 + Azure SQLPCI compliance
Inventory.NET 9 + Azure SQLConsistency critical
NotificationAzure FunctionsEvent-driven, scale to zero
MessagingAzure Service Bus (Topics)Reliable, managed
CachingRedis (HybridCache)Performance
SearchAzure AI SearchFull-text, facets
StorageBlob Storage + CDNProduct images
AuthAzure AD B2C + JWTCustomer auth
MonitoringApp Insights + GrafanaFull observability

2. Logistics Tracking System

┌────────────────────────────────────────────────────────────────┐
│                  Logistics Tracking System                      │
│                                                                 │
│  ┌──────────┐   ┌──────────┐   ┌──────────┐   ┌────────────┐ │
│  │ Mobile   │   │ Web      │   │ Partner  │   │ IoT        │ │
│  │ App      │   │ Portal   │   │ APIs     │   │ Devices    │ │
│  └────┬─────┘   └────┬─────┘   └────┬─────┘   └────┬───────┘ │
│       │              │              │              │          │
│  ┌────▼──────────────▼──────────────▼──────────────▼────────┐ │
│  │              API Gateway (YARP)                           │ │
│  └──────┬────────────┬────────────┬────────────┬────────────┘ │
│         │            │            │            │               │
│  ┌──────▼──┐  ┌──────▼──┐  ┌─────▼───┐  ┌────▼─────┐       │
│  │Shipment │  │Tracking │  │Routing  │  │Billing  │       │
│  │Service  │  │Service  │  │Service  │  │Service  │       │
│  │         │  │         │  │         │  │         │       │
│  │ SQL     │  │Cosmos   │  │ SQL +   │  │ SQL     │       │
│  │         │  │ + Redis │  │ Maps API│  │         │       │
│  └─────────┘  └─────────┘  └─────────┘  └─────────┘       │
│                    │                                         │
│              ┌─────▼──────┐                                  │
│              │ SignalR    │  Real-time GPS tracking          │
│              │ + Event    │  Event streaming                 │
│              │ Hubs       │                                  │
│              └────────────┘                                  │
└────────────────────────────────────────────────────────────────┘

Key Design Decisions:
- Cosmos DB cho Tracking: high write throughput, global distribution
- SignalR cho real-time GPS tracking to web/mobile
- Azure Maps cho route optimization
- Event-driven: shipment status changes → notifications
- IoT Hub cho device data ingestion

3. Financial System

┌────────────────────────────────────────────────────────────────┐
│                   Financial System                              │
│                                                                 │
│  ┌──────────┐         ┌────────────────────────────────┐       │
│  │ React    │────────→│  API Gateway                   │       │
│  │ + Vite   │         │  (Auth + Rate Limiting)        │       │
│  │ (SPA)    │         └──────┬──────────┬──────────────┘       │
│  └──────────┘                │          │                      │
│                        ┌─────▼────┐ ┌───▼──────────┐          │
│                        │Account  │ │Transaction  │          │
│                        │Service  │ │Service      │          │
│                        │         │ │             │          │
│                        │ SQL     │ │ SQL (Event  │          │
│                        │ (ACID)  │ │ Sourcing)   │          │
│                        └─────────┘ └──────┬──────┘          │
│                                           │                  │
│                                    ┌──────▼──────┐           │
│                                    │ ADF ETL     │           │
│                                    │ Pipeline    │           │
│                                    │             │           │
│                                    │ → Data Lake │           │
│                                    │ → DW        │           │
│                                    │ → Power BI  │           │
│                                    └─────────────┘           │
│                                                               │
│  ⚠️ Compliance Requirements:                                  │
│  - Event Sourcing cho full audit trail                        │
│  - Encryption at rest + in transit                            │
│  - PCI DSS / SOC 2 compliance                                │
│  - Data residency (specific Azure region)                     │
│  - Key Vault cho all secrets                                  │
│  - Private Endpoints (no public access to DB)                 │
└────────────────────────────────────────────────────────────────┘

Key Design Decisions:
- Event Sourcing cho Transaction Service (audit trail bắt buộc)
- React + Vite SPA (internal dashboard, no SEO needed)
- ADF cho ETL to reporting/DW
- Strict security: Private Endpoints, WAF, encryption

4. Insurance Portal

┌────────────────────────────────────────────────────────────────┐
│                    Insurance Portal                             │
│                                                                 │
│  ┌──────────┐         ┌────────────────────────────────┐       │
│  │ Next.js  │────────→│  API Gateway (YARP)            │       │
│  │ (SSR)    │         └──────┬──────────┬──────┬───────┘       │
│  └──────────┘                │          │      │               │
│                        ┌─────▼────┐ ┌───▼────┐│               │
│                        │ Policy   │ │ Claims ││               │
│                        │ Service  │ │ Service││               │
│                        │          │ │        ││               │
│                        │ SQL +    │ │ SQL +  ││               │
│                        │ Blob     │ │ Blob   ││               │
│                        └──────────┘ └────────┘│               │
│                                               │               │
│                        ┌──────────────────────▼──────────┐    │
│                        │  Durable Functions               │    │
│                        │  Claims Processing Workflow      │    │
│                        │                                  │    │
│                        │  Submit → Validate → Review     │    │
│                        │  → Approve/Reject → Pay         │    │
│                        │  → Notify                       │    │
│                        └─────────────────────────────────┘    │
│                                                               │
│  Integrations:                                                │
│  - Azure AI (Document Intelligence): OCR claim documents      │
│  - Blob Storage: policy documents, claim photos               │
│  - PDF generation: policy certificates                        │
│  - Email/SMS notifications via Azure Communication Services   │
└────────────────────────────────────────────────────────────────┘

Key Design Decisions:
- Durable Functions cho claims workflow (long-running, human approval)
- Azure AI Document Intelligence cho OCR
- Blob Storage + SAS tokens cho secure document access
- Next.js SSR cho public portal (SEO + authenticated sections)

5. Architecture Decision Framework

Checklist cho Mỗi Dự Án

□ 1. Architecture Style
    ├── Monolith (team <10, MVP, simple domain)
    ├── Modular Monolith (team 10-20, growing complexity)
    └── Microservices (team >20, independent scaling needed)

□ 2. Frontend
    ├── Next.js (public + SEO)
    ├── React + Vite (internal admin)
    └── Both (public portal + admin dashboard)

□ 3. Data Store
    ├── Azure SQL (ACID, complex queries, EF Core)
    ├── Cosmos DB (global, flexible schema, high throughput)
    ├── Redis (caching, sessions)
    └── Blob Storage (files, documents)

□ 4. Communication
    ├── Sync: REST (public) / gRPC (internal)
    └── Async: Service Bus (reliable) / Event Grid (events)

□ 5. Compute
    ├── Container Apps (microservices, scale to zero)
    ├── App Service (simple web apps)
    ├── Functions (event-driven, background)
    └── AKS (complex orchestration, multi-team)

□ 6. Security
    ├── Azure AD / AD B2C (authentication)
    ├── Key Vault (secrets)
    ├── Managed Identity (service-to-service)
    └── Private Endpoints (network isolation)

□ 7. Observability
    ├── OpenTelemetry (tracing)
    ├── Serilog + Seq / App Insights (logging)
    ├── Prometheus + Grafana (metrics)
    └── Health checks (readiness/liveness)

6. Best Practices Summary

Code Quality

✅ Clean Architecture: dependency inversion
✅ Rich Domain Model: business logic trong entities
✅ CQRS: tách read/write khi cần
✅ MediatR + Pipeline Behaviors: cross-cutting concerns
✅ FluentValidation: input validation
✅ Result Pattern: no exceptions for business errors

Infrastructure

✅ Docker: multi-stage build, non-root user
✅ CI/CD: automated test → build → deploy
✅ IaC: Bicep/Terraform cho reproducible infrastructure
✅ .NET Aspire: dev orchestration
✅ Feature Flags: safe deployments (Azure App Configuration)

Data

✅ EF Core: migrations, interceptors, compiled queries
✅ Outbox Pattern: reliable event publishing
✅ Idempotent Consumers: handle duplicate messages
✅ Caching: HybridCache (.NET 9), Redis
✅ Incremental ETL: ADF with watermark pattern

Security

✅ Managed Identity: no credentials in code
✅ Key Vault: centralized secrets
✅ CORS + Security Headers: defense in depth
✅ Rate Limiting: protect APIs
✅ Data Protection API: encrypt sensitive data

Tổng Kết Session 24 & Toàn Bộ Roadmap

Learning Path Completed 🎉

PhaseSessionsKey Skills
1. .NET Core01-06CLR, C# 12, ASP.NET Core, EF Core, Performance, Security
2. Frontend07-11React Advanced, Next.js, Vite, Integration
3. Architecture12-18Clean/DDD, CQRS, Modular Monolith, Microservices, Saga
4. Azure19-24Platform, Service Bus, Functions, ADF, DevOps, Enterprise

Con Đường Tiếp Theo

Level 1: Master (bạn đang ở đây!)
  ✅ Deep .NET knowledge
  ✅ Frontend integration
  ✅ Architecture patterns
  ✅ Azure cloud services

Level 2: Expert
  → System Design interviews
  → Open source contributions
  → Conference talks / Blog posts
  → Mentoring junior developers

Level 3: Architect
  → Enterprise architecture governance
  → Technology strategy & roadmap
  → Cross-team technical leadership
  → Cloud cost optimization

Final Project: Chọn 1 industry (eCommerce, Logistics, Finance, Insurance), thiết kế full system: architecture diagram, technology stack, database schema, CI/CD pipeline, và deploy MVP lên Azure.