Architecture and Scalability

$ whoami

$ whoami

Software Developer

Jul 2013

Jul 2014

Snr. Software Developer

Jul 2015

Technical Lead

Aso. Architect

Jan

2018

Jan 2020

Soft.

Architect

Architecture

Software architecture refers to the high level structures of a software system, the discipline of creating such structures, and the documentation of these structures.

Src: Wikipedia

Architecture

 

  • Choices which are costly to change once implemented

 

  • General understanding of how a system works

Architecture

How we should have built the software system

Architecture

  • Simple
  • Maintainable
  • Scalable
  • Fault tolerant
  • Cost effective

A NOT scalable codebase

time

features

Difficult to add features overtime

A scalable codebase

time

features

Easier to add features overtime

Factors

  • Structure
  • Modularity
  • Readability
  • Repetition for separation

L

I

F

T

Locate the code easily

Identifiable at a glance

Flat structure as much as possible

Try to stay DRY (Don't repeat yourself)

Credit: John Papa

L

Locate the code easily

Which is the controller layer?

Which is the service layer?

WTH is Elixir?

L

Locate the code easily

No need to say anything here ...

Modularity

Break it when you think its doing too much or an entirely different thing

Read Code > Write Code

Meaningful Names

function mashIt(x, y) {
  let retVal = x / y;
  return retVal;
}
function divide(dividend, divisor) {
  let result = dividend / divisor;
  return result;
}

Descriptive Names

function helper.remove (x, y) {
  delete x[y];
  return x;
}
function deleteProperty(obj, prop) {
  delete obj[prop]
  return obj;
}

Correct Names

function delCostomer (x, y) {
  // some logic 
  // to delete costomer
}
function deleteCustomer(obj, prop) {
  // some logic 
  // to delete customer
}

Readable Functions

  • Do exactly one thing
  • Don't tend to be huge
  • Shouldn't have too much nesting
  • Shouldn't have too much complexity

Don't Repeat Yourself

  • Don't DRY too much
  • Don't DRY too little

Look for patterns to make the right decision instead of searching for the silver bullet

Infrastructure

  • Memory Pressure
  • Compute Pressure
  • Network Pressure

Scale

vertical/up or horizontal/out

Memory: 1 GB

vCPU: 2

Memory: 2 GB

vCPU: 4

Memory: 1 GB

vCPU: 2

up/vertical

out/horizontal

How do I know when to scale ?

Monitor

CloudWatch

X Ray

How to scale out ?

Internet

App Server

Database

Internet

Load balancer

App Servers

DB
Cluster

Can't scale out ?

Look for opportunities to cache frequently accessed data in memory

App Server

Cached data

App Memory

In-memory cache

Internet

App Server

Database

Something is fishy

Internet

Load balancer

App Servers

with in-memory cache

DB
Cluster

Distributed Cache

Internet

Load balancer

App Servers

DB
Cluster

Distributed Cache Servers

Caching as a Service

Redis Cache

ElastiCache

Microservices and containers

Some other time!!

Storage types

  • Block
  • File
  • Object

Storage as a Service

Block Storage

S3

Glacier

File Storage

Page Blob

Block Blob

Files

Storage

Databases

Databases need to scale as well

Vertical/Up

Works the same way

Horizontal/Out

  • Sharding
  • Replication

Database as a Service

SQL

CosmosDB

RDS

DynamoDB

Database as a Service

Architecture needs to be built for

  • Fault tolerance
  • Disaster recovery

0 downtime deployments

Blue/Green Deployments

Compute
Compute
Compute
Compute

Managed Deployment Services

AKS

AppService

EBS

ECS

EKS

Architecture in diagrams

  • Knowledge Wiki
  • Component
  • Infrastructure
  • Database

10Pearls Wiki

Login with your COGS credentials

Analyze wants against needs

Not every project needs cross-region replication

Architecture and Scalability

By Mohammad Umair Khan

Architecture and Scalability

  • 1,169