# sap-archive/cap-distributed-resiliency architecture

> Architecture diagram of the GitHub repository sap-archive/cap-distributed-resiliency, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sap-archive/cap-distributed-resiliency
- Repository: https://github.com/sap-archive/cap-distributed-resiliency

## Overview

##### Project Type and Purpose
- This is an open-source sample repository providing reference blueprints and code snippets for implementing distributed, active-active resiliency in SAP Cloud Application Programming (CAP) applications on SAP Business Technology Platform (BTP), using either Azure (SAP HANA Cloud + Azure Traffic Manager) or AWS (Amazon Aurora + Route 53).
- There is no single runnable codebase here, but rather two scenario implementations (in separate branches or folders) showcasing best practices for cross-region failover and multi-zone replication.

##### File Structure
- Top-level files:
- README.md – describes purpose, scenarios, patterns
- LICENSE / LICENSES – licensing details
- CODE_OF_CONDUCT.md – contributor guidelines
- Scenario implementations live in separate branches or subdirectories (e.g., “SAP-HANA-Cloud”, “Amazon-Aurora”), each containing a small CAP service, deployment manifests, infrastructure as code, and step-by-step instructions.
- Other directories (.reuse, .vscode) hold metadata and IDE settings, not core architecture code.

##### README Insights
- Two primary resiliency scenarios:
a. SAP HANA Cloud cross-zone replication + Azure Traffic Manager for DNS-based geo-load balancing
b. Amazon Aurora read replicas + Amazon Route 53 for active-active database failover
- Emphasizes distributed resiliency patterns on SAP BTP across multiple Availability Zones and regions.

##### Main Components
a. SAP CAP Application (deployed as microservices on SAP BTP Cloud Foundry or Kyma)
b. API / Application Gateway (SAP BTP API Management or Cloud Foundry router)
c. DNS / Traffic Management Layer (Azure Traffic Manager or Amazon Route 53)
d. Two or more regional deployments (Region A, Region B)
– Each region has:
- CAP microservice instances (multiple AZs)
- SAP HANA Cloud (multi-zone) or Amazon Aurora (primary + read-replica)
e. Inter-region database replication (HANA multi-zone replication or Aurora cross-region replicas)
f. External clients or UIs (SAP Launchpad, web/mobile clients)

##### Relationships and Interactions
- Client → DNS/TM → region endpoint
- DNS/TM continuously monitors health checks in both regions
- Region endpoint load-balances incoming requests across AZs
- CAP microservices process requests, read/write to local DB
- DB replication ensures data synchronization across regions
- On regional failure, DNS/TM reroutes traffic to healthy region

##### Architectural Patterns and Principles
- Active-active deployment across regions
- Multi-zone replication within each region
- Health-check-driven DNS failover
- Circuit breaker and retry logic in CAP services
- Infrastructure as Code for reproducible deployments

##### Key Technologies / Frameworks
- SAP CAP (Node.js or Java)
- SAP BTP Cloud Foundry runtime or Kyma runtime
- SAP HANA Cloud multi-zone replication
- Azure Traffic Manager (Geo, Priority routing)
- Amazon Aurora Global Database / Read Replicas
- Amazon Route 53 health-check failover
- IaC (Terraform/Cloud Formation/Multi-Service YAML)

##### Detail and Clarity
- Fallback paths and failover cut-over logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External Users" 
        direction TB
        Clients["Users / SAP Launchpad"]:::ext
    end

    %% DNS / Traffic Manager
    DNS["Azure Traffic Manager / Route 53"]:::infra
    Clients -->|"HTTP / HTTPS"| DNS

    %% Region A
    subgraph "Region A" 
        direction TB
        subgraph "Availability Zone AZ1"
            direction TB
            CFRouterA1["CF Router / API Gateway"]:::backend
            CAPSvcA1["CAP Node Service"]:::backend
            CFRouterA1 -->|HTTP| CAPSvcA1
        end
        subgraph "Availability Zone AZ2"
            direction TB
            CFRouterA2["CF Router / API Gateway"]:::backend
            CAPSvcA2["CAP Node Service"]:::backend
            CFRouterA2 -->|HTTP| CAPSvcA2
        end
        DBClusterA["SAP HANA Cloud / Aurora Cluster"]:::db
        CAPSvcA1 -->|"Read/Write"| DBClusterA
        CAPSvcA2 -->|"Read/Write"| DBClusterA
    end

    %% Region B
    subgraph "Region B"
        direction TB
        subgraph "Availability Zone AZ1"
            direction TB
            CFRouterB1["CF Router / API Gateway"]:::backend
            CAPSvcB1["CAP Node Service"]:::backend
            CFRouterB1 -->|HTTP| CAPSvcB1
        end
        subgraph "Availability Zone AZ2"
            direction TB
            CFRouterB2["CF Router / API Gateway"]:::backend
            CAPSvcB2["CAP Node Service"]:::backend
            CFRouterB2 -->|HTTP| CAPSvcB2
        end
        DBClusterB["SAP HANA Cloud / Aurora Cluster"]:::db
        CAPSvcB1 -->|"Read/Write"| DBClusterB
        CAPSvcB2 -->|"Read/Write"| DBClusterB
    end

    %% DNS health checks and routing
    DNS -->|Health Check| CFRouterA1
    DNS -->|Health Check| CFRouterB1
    DNS -->|"Geo / Priority Routing"| CFRouterA1
    DNS -->|"Geo / Priority Routing"| CFRouterB1

    %% Cross-Region Replication
    DBClusterA <-->|"Cross-Region Replication"| DBClusterB

    %% Legend and Documentation
    subgraph "Project Documentation" 
        direction TB
        README["README.md"]:::doc
        CodeCond["CODE_OF_CONDUCT.md"]:::doc
        License["LICENSE"]:::doc
        License2["Apache-2.0.txt"]:::doc
        Reuse[".reuse/"]:::meta
        VSCode[".vscode/"]:::meta
    end

    %% Click Events
    click README "https://github.com/sap-archive/cap-distributed-resiliency/blob/main/README.md"
    click CodeCond "https://github.com/sap-archive/cap-distributed-resiliency/blob/main/CODE_OF_CONDUCT.md"
    click License "https://github.com/sap-archive/cap-distributed-resiliency/tree/main/LICENSE"
    click License2 "https://github.com/sap-archive/cap-distributed-resiliency/blob/main/LICENSES/Apache-2.0.txt"
    click Reuse "https://github.com/sap-archive/cap-distributed-resiliency/tree/main/.reuse/"
    click VSCode "https://github.com/sap-archive/cap-distributed-resiliency/tree/main/.vscode/"

    %% Styles
    classDef ext fill:#B3E5FC,stroke:#0288D1,color:#000
    classDef infra fill:#E1BEE7,stroke:#8E24AA,color:#000
    classDef backend fill:#C8E6C9,stroke:#2E7D32,color:#000
    classDef db fill:#FFE0B2,stroke:#EF6C00,color:#000
    classDef doc fill:#FFF9C4,stroke:#FBC02D,color:#000
    classDef meta fill:#ECEFF1,stroke:#90A4AE,color:#000
```
