Skip to content

Instantly share code, notes, and snippets.

@loftwah
Last active February 28, 2024 07:56
Show Gist options
  • Save loftwah/2ade41232b6470c8e5fc020b4b922e9d to your computer and use it in GitHub Desktop.
Save loftwah/2ade41232b6470c8e5fc020b4b922e9d to your computer and use it in GitHub Desktop.
Diagram

Diagrams

Three regions with the same architecture, each with an AWS Load Balancer, EC2 instances in an Auto Scaling Group, RDS Postgres DB, Elasticache Redis, Elasticache Memcached, S3, SQS, SNS, SES.

graph TD
    subgraph ap-southeast-2 [ap-southeast-2 Region]
        ALB_A[(AWS Load Balancer)]
        EC2_ASG_A[EC2 Instances - ASG]
        RDS_PG_A[RDS - Postgres DB]
        REDIS_EC_A[(Elasticache Redis)]
        MEMCACHED_EC_A[(Elasticache Memcached)]
        S3_A[S3 - Static Assets]
        SQS_A[SQS - Job Queuing]
        SNS_A[SNS - Push Notifications]
        SES_A[SES - Email Service]

        ALB_A --> EC2_ASG_A
        EC2_ASG_A -->|Read/Write| RDS_PG_A
        EC2_ASG_A -->|Cache| REDIS_EC_A
        EC2_ASG_A -->|Cache| MEMCACHED_EC_A
        EC2_ASG_A -->|Static assets| S3_A
        EC2_ASG_A -->|Job queue| SQS_A
        SQS_A -->|Notifications| SNS_A
        EC2_ASG_A -->|Emails| SES_A
    end

    subgraph eu-west-1 [eu-west-1 Region]
        ALB_B[(AWS Load Balancer)]
        EC2_ASG_B[EC2 Instances - ASG]
        RDS_PG_B[RDS - Postgres DB]
        REDIS_EC_B[(Elasticache Redis)]
        MEMCACHED_EC_B[(Elasticache Memcached)]
        S3_B[S3 - Static Assets]
        SQS_B[SQS - Job Queuing]
        SNS_B[SNS - Push Notifications]
        SES_B[SES - Email Service]

        ALB_B --> EC2_ASG_B
        EC2_ASG_B -->|Read/Write| RDS_PG_B
        EC2_ASG_B -->|Cache| REDIS_EC_B
        EC2_ASG_B -->|Cache| MEMCACHED_EC_B
        EC2_ASG_B -->|Static assets| S3_B
        EC2_ASG_B -->|Job queue| SQS_B
        SQS_B -->|Notifications| SNS_B
        EC2_ASG_B -->|Emails| SES_B
    end

    subgraph us-west-1 [us-west-1 Region]
        ALB_C[(AWS Load Balancer)]
        EC2_ASG_C[EC2 Instances - ASG]
        RDS_PG_C[RDS - Postgres DB]
        REDIS_EC_C[(Elasticache Redis)]
        MEMCACHED_EC_C[(Elasticache Memcached)]
        S3_C[S3 - Static Assets]
        SQS_C[SQS - Job Queuing]
        SNS_C[SNS - Push Notifications]
        SES_C[SES - Email Service]

        ALB_C --> EC2_ASG_C
        EC2_ASG_C -->|Read/Write| RDS_PG_C
        EC2_ASG_C -->|Cache| REDIS_EC_C
        EC2_ASG_C -->|Cache| MEMCACHED_EC_C
        EC2_ASG_C -->|Static assets| S3_C
        EC2_ASG_C -->|Job queue| SQS_C
        SQS_C -->|Notifications| SNS_C
        EC2_ASG_C -->|Emails| SES_C
    end

    Client -->|DNS lookup| CF[Cloudflare]
    CF -->|Routes to nearest region| ALB_A
    CF -->|Routes to nearest region| ALB_B
    CF -->|Routes to nearest region| ALB_C

Single Region

graph TD
    ALB[(AWS Load Balancer)]
    EC2Web[EC2 Web Server]
    EC2App[EC2 Application Server]
    EC2Worker[EC2 Worker]
    RDS_PG[RDS - Postgres DB]
    Redis[(Elasticache Redis)]
    Memcached[(Elasticache Memcached)]
    S3[S3 - Static Assets]
    SQS[SQS - Job Queuing]
    SNS[SNS - Push Notifications]
    SES[SES - Email Service]
    RDS_SNAPSHOTS[RDS Snapshots]
    RDS_REPLICA[RDS Read Replica]
    S3_REPLICA[S3 Replica Bucket]
    SEMAPHORECI[SemaphoreCI]
    CUSTOMPANEL[Custom Deployment Panel]
    RAKE[Rake Tasks]
    CLOUDWATCH[CloudWatch]
    SG[Security Groups]
    IAM[IAM Roles]
    ACL[Network ACLs]

    ALB -->|Distributes traffic| EC2Web
    ALB -->|Distributes traffic| EC2App
    ALB -.->|Health checks| EC2Worker
    EC2Web -->|Serves static content| S3
    EC2App -->|Read/Write| RDS_PG
    EC2App -->|Cache| Redis
    EC2App -->|Cache| Memcached
    EC2Worker -->|Process jobs| SQS
    SQS -->|Trigger| SNS
    SNS -->|Notifications| MobileApp[Mobile App - Cordova]
    EC2App -->|Send emails| SES
    RDS_PG -.->|Daily incremental backups| RDS_SNAPSHOTS
    RDS_PG -->|Real-time replication| RDS_REPLICA
    S3 -.->|Cross-region replication| S3_REPLICA
    SEMAPHORECI -.->|Continuous Integration| EC2Web
    SEMAPHORECI -.->|Continuous Integration| EC2App
    SEMAPHORECI -.->|Continuous Integration| EC2Worker
    CUSTOMPANEL -.->|Deployment| EC2Web
    CUSTOMPANEL -.->|Deployment| EC2App
    CUSTOMPANEL -.->|Deployment| EC2Worker
    RAKE -.->|Command-line tasks| EC2App
    CLOUDWATCH -.->|Monitoring & Logging| EC2App
    CLOUDWATCH -.->|Monitoring & Logging| EC2Web
    CLOUDWATCH -.->|Monitoring & Logging| EC2Worker
    SG -.->|Firewall| ALB
    IAM -.->|Access control| EC2App
    IAM -.->|Access control| S3
    ACL -.->|Network rules| VPC[Virtual Private Cloud]

Application Architecture Sub-Diagrams

This document breaks down the main application architecture into several sub-diagrams, each focusing on a particular aspect of the system.

Traffic Distribution and Health Checks

graph TD
    ALB[(AWS Load Balancer)] -->|Distributes traffic| EC2Web[EC2 Web Server]
    ALB -->|Distributes traffic| EC2App[EC2 Application Server]
    ALB -.->|Health checks| EC2Worker[EC2 Worker]

This diagram shows how the AWS Load Balancer distributes incoming traffic to the web and application servers and performs health checks on worker instances.

Data Storage and Replication

graph TD
    EC2App[EC2 Application Server] -->|Read/Write| RDS_PG[RDS - Postgres DB]
    RDS_PG -.->|Daily incremental backups| RDS_SNAPSHOTS[RDS Snapshots]
    RDS_PG -->|Real-time replication| RDS_REPLICA[RDS Read Replica]

This sub-diagram focuses on the PostgreSQL database, including how it is accessed by the application server, its backup strategy, and replication setup.

Caching Layer

graph TD
    EC2App[EC2 Application Server] -->|Cache| Redis[(Elasticache Redis)]
    EC2App -->|Cache| Memcached[(Elasticache Memcached)]

Here we see the caching layer of the architecture, depicting the application server's interaction with Redis and Memcached for caching.

Static Content Delivery and Replication

graph TD
    EC2Web[EC2 Web Server] -->|Serves static content| S3[S3 - Static Assets]
    S3 -.->|Cross-region replication| S3_REPLICA[S3 Replica Bucket]

This sub-diagram shows how static content is served from S3, and how the data is replicated across regions for redundancy.

Job Processing and Notifications

graph TD
    EC2Worker[EC2 Worker] -->|Process jobs| SQS[SQS - Job Queuing]
    SQS -->|Trigger| SNS[SNS - Push Notifications]
    SNS -->|Notifications| MobileApp[Mobile App - Cordova]

This diagram illustrates the flow of job processing, from the worker instances through the job queue, to triggering notifications that are sent to the mobile application.

Email Service

graph TD
    EC2App[EC2 Application Server] -->|Send emails| SES[SES - Email Service]

A simple representation of how the application server sends emails using the Amazon Simple Email Service.

Continuous Integration and Deployment

graph TD
    SEMAPHORECI[SemaphoreCI] -.->|Continuous Integration| EC2Web[EC2 Web Server]
    SEMAPHORECI -.->|Continuous Integration| EC2App[EC2 Application Server]
    SEMAPHORECI -.->|Continuous Integration| EC2Worker[EC2 Worker]
    CUSTOMPANEL[Custom Deployment Panel] -.->|Deployment| EC2Web
    CUSTOMPANEL -.->|Deployment| EC2App
    CUSTOMPANEL -.->|Deployment| EC2Worker
    RAKE[Rake Tasks] -.->|Command-line tasks| EC2App

This sub-diagram shows how SemaphoreCI is used for continuous integration and the role of a custom deployment panel and Rake tasks in the deployment process.

Security and Access Control

graph TD
    SG[Security Groups] -.->|Firewall| ALB[(AWS Load Balancer)]
    IAM[IAM Roles] -.->|Access control| EC2App[EC2 Application Server]
    IAM -.->|Access control| S3[S3 - Static Assets]
    ACL[Network ACLs] -.->|Network rules| VPC[Virtual Private Cloud]

The final sub-diagram details the security measures in place, including security groups, IAM roles, and network ACLs within the VPC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment