Components of a Distributed System PRATEEK PAREKH SOFTWARE ENGINEER - - PowerPoint PPT Presentation

components of a distributed system
SMART_READER_LITE
LIVE PREVIEW

Components of a Distributed System PRATEEK PAREKH SOFTWARE ENGINEER - - PowerPoint PPT Presentation

Components of a Distributed System PRATEEK PAREKH SOFTWARE ENGINEER @ prparekh83 t h s Building the Front-end Layer Module Overview Handling Business logic with Web Services Understanding the Data Layer Asynchronous Processing Building


slide-1
SLIDE 1

@ prparekh83

SOFTWARE ENGINEER

PRATEEK PAREKH

Components of a Distributed System

slide-2
SLIDE 2

t h s

Building the Front-end Layer Handling Business logic with Web Services Understanding the Data Layer Asynchronous Processing

Module Overview

slide-3
SLIDE 3

Building the Front-end Layer

slide-4
SLIDE 4

Front end servers

Customer Load Balancer Search Servers CDN Message Queue Servers Database servers

Batch job Servers

Back end servers

Cache Servers Internet DNS

slide-5
SLIDE 5

User Session

State management

Memory Local files Resource Locks

slide-6
SLIDE 6

Keep your Servers Stateless. Scale Horizontally by adding more Servers.

slide-7
SLIDE 7

s h s

Client and server communicate over HTTP HTTP protocol is stateless Establish HTTP session with Cookies in request and response headers

State Management

slide-8
SLIDE 8

State management

Client Server GET /home.html Set-cookie:SID=EMPTY Response header Set-cookie:SID=abc… GET /forum.html Cookie:SID=abc… Response with HTML content

slide-9
SLIDE 9

s h s

Cookies sent with every individual request Store session data in an external datastore For local files, use CDN or an Object store

State Management

slide-10
SLIDE 10

State management

Client Server GET /home.html Set-cookie:SID=EMPTY Response header Set-cookie:SID=abc… GET /forum.html Cookie:SID=abc… Response with HTML content save session success fetch/save session success Redis

slide-11
SLIDE 11

DNS - Domain Name System (eg. Route 53, easydns.com)

Front-end Layer Components

CDN - Content Delivery Network (eg. Akamai, Amazon CloudFront) Load Balancer (eg. Elastic Load Balancer, HAProxy, Nginx) Caching (eg. Browser, Redis/Memcached)

slide-12
SLIDE 12

Deploying Robomantics Frontend on AWS

EC2 Front end servers cluster

Customer Elastic Load Balancer (ELB) Cloudfront CDN Public S3 buckets Route 53 DNS HTTP requests static files dynamic content distribute requests Backend servers instance 1 instance n Amazon Auto Scale Amazon CloudWatch Service Private S3 buckets

slide-13
SLIDE 13

Handling Business Logic with Web Services

slide-14
SLIDE 14

Front end servers

Customer Load Balancer Search Servers CDN Message Queue Servers Database servers

Batch job Servers

Back end servers

Cache Servers Internet DNS

slide-15
SLIDE 15

Web Services encapsulates the business logic and hides complexity behind an API contract

slide-16
SLIDE 16

Order Payment Checkout Search Catalog Account

Globomantics Web Service Layer

slide-17
SLIDE 17

Split a large system into a set of smaller, loosely coupled and independent web services – each focusing on a subset of functionality of the overall system

Functional Partitioning

slide-18
SLIDE 18

Functional partition Front end servers Account Service Load balancer Catalog Service MySQL database Cassandra database Mobile client Partner Integration

slide-19
SLIDE 19

Re Resource oriented architectural style that defines a set

  • f co

constraints used for creating web services

REST

slide-20
SLIDE 20

HTTP GET Request: URL http://globomantics.com/order/123456

JSON Response

{ “OrderID”: “123456”, “Date”: “09/12/2020”, “Status”: “Delivered” }

slide-21
SLIDE 21

s h s

Leverage HTTP features (PUT, GET, POST) Status codes (200 – OK, 400 – Bad Request) Security Controls Caching Ecosystem of Monitoring tools

Why REST?

slide-22
SLIDE 22

Easy Maintenance

Zero downtime update of services Isolate Server Failures

Servers routinely ping load balancer

Load Balancers

Between clients and backend servers Stateless Servers

Scale by adding replica servers (AutoScale)

No Shared Store

Use Cache, Database and MessageQueues

Scaling Web Services

slide-23
SLIDE 23

Distributed Transactions

Implementing an operation consisting of a set of web service calls that should either fail or pass?

slide-24
SLIDE 24

Order Service

Payment Service Shipping Service

Client charge ship rollback

Distributed Transaction Failure

Response HTTP PUT Request Create Order

slide-25
SLIDE 25

Understanding the Data Layer

slide-26
SLIDE 26

Replication

Synchronize state between 2 servers (master and slave) Scale read throughput and provide higher availability Each server holds an identical copy of data

slide-27
SLIDE 27

Master Slaves

Master-Slave Replication

write read sync sync client

slide-28
SLIDE 28

s h s

Introduces complexity Replication lag Only applicable for scaling reads

Replication Challenges

slide-29
SLIDE 29

Sharding (Partitioning)

Divide dataset into smaller chunks Each server processes only a subset of data Isolate failure of servers from each other

slide-30
SLIDE 30

Determines the distribution of the dataset among your servers (shards or partitions)

Sharding key

slide-31
SLIDE 31

Server 1 Server 10

Modulo-based Sharding

UserID 113321 Sharding Function Input

slide-32
SLIDE 32

s h s

Sharding function can be complex Mappings can break Querying data across shards

Sharding Challenges

slide-33
SLIDE 33

States that it’s impossible to build a distributed system that would simultaneously guarantee Consistency, Availability and Partition Tolerance

CAP Theorem

slide-34
SLIDE 34

Partition Tolerance

System is functional even when servers cannot communicate

Availability

Server can process requests even when

  • ther servers are down

Consistency

All servers see the same data

CAP Theorem

slide-35
SLIDE 35

CP Database

MongoDB Stores data as BSON documents Single Master-Slave configuration Server shutdown during partition

AP Database

Cassandra Wide column database Masterless configuration Server remains available

CAP Theorem and NoSQL

slide-36
SLIDE 36

Handling Asynchronous Communication

slide-37
SLIDE 37

A call is made to a remote server, which blocks until the

  • peration completes

Synchronous Communication

slide-38
SLIDE 38

Item Service

Database/ Cache

Browser fetch return

Synchronous Communication Example

load page Load Item Page blocking data unblock

slide-39
SLIDE 39

The caller doesn’t wait for the operation to complete before returning

Asynchronous Communication

slide-40
SLIDE 40

Event-based

Client emits events. Subscribers react independently

Callback

Register a callback to be notified when the

  • peration completes

Fire and Forget

Caller doesn’t care if the operation completes or not

Asynchronous Communication Patterns

slide-41
SLIDE 41

Checkout

Payment Shipping

Mobile charge payment approved

Asynchronous Communication Example

Order Confirmation Email Checkout Cart Place Order Thanks for your Order callback async

slide-42
SLIDE 42

Message Queues

slide-43
SLIDE 43

Message Queues

Buffers and Distributes Asynchronous requests Messages are platform independent (JSON, XML) Producers and Consumers run as separate processes and hosted on separate servers Messages are platform independent (JSON, XML)

slide-44
SLIDE 44

s h s

Initiate asynchronous calls Create a message and push it to the Queue Message format serves as the contract

Producers

slide-45
SLIDE 45

<?xml version=“1.0”> <message> <invoice date=“01-15-2020” id=“321332”> <item>1234432321</item> <title>A Brief History of Nearly Everything – Bill Bryson</title> <USPrice>12.99</USPrice> . . .

Custom Message Format Example

Serves as the contract between Producers and Consumers

slide-46
SLIDE 46

s h s

Provides the following features

  • Message queuing
  • Persisting
  • Routing and Delivery

Configuration over Customization Support higher thoroughput and Scalability

Message Broker

slide-47
SLIDE 47

s h s

Process requests asynchronously Implemented in the application code

  • Pull model
  • Push model

Consumers

slide-48
SLIDE 48

Message Routing

slide-49
SLIDE 49

Direct Worker Queue Method

Single Work Queue identified by name Multiple Producers and Consumers Each Message routed to one Consumer Ideal for long running tasks

  • Video Transcoding
  • Data classification
  • Image resizing
slide-50
SLIDE 50

Work Queue Consumer 1 Consumer N

Globomantics Batch Server

Batch Servers Producer 1 Producer N Backend Servers Item Listed Create Thumbnail

slide-51
SLIDE 51

Front end servers

Customer Load Balancer Search Servers CDN Message Queue Servers Database servers

Batch job Servers

Back end servers

Cache Servers Internet DNS

slide-52
SLIDE 52

t h s

Front-end Layer

  • State management
  • DNS, CDN, Load balancer, Caching

Web Services Layer

  • Functional Partitioning
  • REST

Data Layer

  • Replication
  • Sharding
  • CAP Theorem

Asynchronous Processing

Summary