leveraging a distributed architecture to your advantage

66
TO YOUR ADVANTAGE LEVERAGING A DISTRIBUTED ARCHITECTURE

Upload: michelangelo-van-dam

Post on 10-Apr-2017

179 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Leveraging a distributed architecture to your advantage

TO YOUR ADVANTAGE LEVERAGING A DISTRIBUTED ARCHITECTURE

Page 2: Leveraging a distributed architecture to your advantage

WHO AM I?

MICHELANGELO VAN DAM

▸ Professional PHP architect

▸ President PHPBenelux

▸ Coach at CoderDojo

▸ Contributor to open source projects

▸ Zend Certified Engineer

Page 3: Leveraging a distributed architecture to your advantage

WHO AM I?

MICHELANGELO VAN DAM

▸ Professional PHP architect

▸ President PHPBenelux

▸ Coach at CoderDojo

▸ Contributor to open source projects

▸ Zend Certified Engineer Rafael Dohms

@rdohms

Page 4: Leveraging a distributed architecture to your advantage

WHO AM I?

MICHELANGELO VAN DAM

▸ Professional PHP architect

▸ President PHPBenelux

▸ Coach at CoderDojo

▸ Contributor to open source projects

▸ Zend Certified Engineer Rafael Dohms

@rdohmsMe

@DragonBe

Page 5: Leveraging a distributed architecture to your advantage

SINGLE LAMP STACK

Page 6: Leveraging a distributed architecture to your advantage

WHAT IS A LAMP STACK?

A COMMON ACRONYM

▸ Linux

▸ Apache

▸ MySQL

▸ PHP

Page 7: Leveraging a distributed architecture to your advantage

PHP

MySQL

Apache

Linux

P

M

A

L

Page 8: Leveraging a distributed architecture to your advantage

WHY USED?

SMALL WEB APPLICATIONS

▸ WordPress blogs

▸ Joomla marketing sites

▸ Drupal business sites

▸ TYPO3 publications

▸ A lot more …

Page 9: Leveraging a distributed architecture to your advantage

SIMPLICITY IS ULTIMATELY A MATTER OF FOCUS.

Ann Voskamp

TWEETABLE QUOTE

Page 10: Leveraging a distributed architecture to your advantage

BENEFITS GALORE

WE LOVE EASY

▸ Single point of concern

▸ Easy to maintain

▸ Easy to distribute

▸ Easy to protect

Page 11: Leveraging a distributed architecture to your advantage

BENEFITS GALORE

WE LOVE EASY

▸ Single point of concern

▸ Easy to maintain

▸ Easy to distribute

▸ Easy to protect

Page 12: Leveraging a distributed architecture to your advantage

NOT ALL SUNSHINE

DOESN'T SCALE WELL

▸ Increase of users

▸ Huge amount of data

▸ Additional logic or features

▸ Compliance requirements

Page 13: Leveraging a distributed architecture to your advantage

MORE WE LIKE

Page 14: Leveraging a distributed architecture to your advantage

Fatalerror:Allowedmemorysizeof268435456bytesexhausted(triedtoallocate77bytes)in/path/to/MassiveClass.phponline666

Page 15: Leveraging a distributed architecture to your advantage

WE NEED TO SCALE!

Page 16: Leveraging a distributed architecture to your advantage

PHP

MySQL

Apache

Linux

P

M

A

L

Page 17: Leveraging a distributed architecture to your advantage

PHP

MySQL

Apache

Linux

P

M

A

L

PHP

MySQL

Apache

Linux

P

M

A

L

PHP

MySQL

Apache

Linux

P

M

A

L

PHP

MySQL

Apache

Linux

P

M

A

L

PHP

MySQL

Apache

Linux

P

M

A

L

PHP

MySQL

Apache

Linux

P

M

A

L

Page 18: Leveraging a distributed architecture to your advantage

PHP

MySQL

Apache

Linux

P

M

A

L

PHP

MySQL

Apache

Linux

P

M

A

L

PHP

MySQL

Apache

Linux

P

M

A

L

PHP

MySQL

Apache

Linux

P

M

A

L

PHP

MySQL

Apache

Linux

P

M

A

L

PHP

MySQL

Apache

Linux

P

M

A

L

Page 19: Leveraging a distributed architecture to your advantage

SCALING MISTAKE #1: DON’T ADD MORE MACHINES AND THINK YOU’RE SCALED.

Remember this!!!

TWEETABLE QUOTE

Page 20: Leveraging a distributed architecture to your advantage

SOME WISDOM

SCALE WITH PURPOSE

▸ Separate based on responsibility

▸ Pinpoint your weakest link

▸ You need more of them

▸ Look for “alternate” (better) solutions

▸ e.g. Nginx vs. Apache

▸ Don’t over-scale

Page 21: Leveraging a distributed architecture to your advantage

PHP-FPM MySQL

LinuxLinux

NGINX

PHP-FPM

Linux

NGINX

Page 22: Leveraging a distributed architecture to your advantage

IS YOUR APP READY TO BE SCALED?

Find the “hard” requirements!

Page 23: Leveraging a distributed architecture to your advantage

ANALYSING YOUR CODE

SOMETHING TO LOOK OUT FOR

resources.db.params.host = "database.server.tld" resources.db.params.port = 3306 resources.db.params.username = "fda23a84" resources.db.params.password = "b10a8db164e0754105b7a99be72e3fe5" resources.db.params.dbname = "webapp" resources.db.isDefaultTableAdapter = true

Page 24: Leveraging a distributed architecture to your advantage

REPLACE WITH SOMETHING THAT CHANGES OUTSIDE YOUR APP

ENVIRONMENT VARIABLES CAN HELP

resources.db.params.host = WEBAPP_DB_HOST resources.db.params.port = WEBAPP_DB_PORT resources.db.params.username = WEBAPP_DB_USERNAME resources.db.params.password = WEBAPP_DB_PASSWORD resources.db.params.dbname = WEBAPP_DB_DBNAME resources.db.isDefaultTableAdapter = WEBAPP_DB_DEFAULT

Page 25: Leveraging a distributed architecture to your advantage

HOW SOMETHING SIMPLE THINGS BECOMES VERY COMPLEX VERY QUICKLY

MORE ITEMS ADDED

Page 26: Leveraging a distributed architecture to your advantage

HOW SOMETHING SIMPLE THINGS BECOMES VERY COMPLEX VERY QUICKLY

MORE ITEMS ADDED

▸ Caching

Page 27: Leveraging a distributed architecture to your advantage

HOW SOMETHING SIMPLE THINGS BECOMES VERY COMPLEX VERY QUICKLY

MORE ITEMS ADDED

▸ Caching

▸ Search engine

Page 28: Leveraging a distributed architecture to your advantage

HOW SOMETHING SIMPLE THINGS BECOMES VERY COMPLEX VERY QUICKLY

MORE ITEMS ADDED

▸ Caching

▸ Search engine

▸ Load balancer

Page 29: Leveraging a distributed architecture to your advantage

HOW SOMETHING SIMPLE THINGS BECOMES VERY COMPLEX VERY QUICKLY

MORE ITEMS ADDED

▸ Caching

▸ Search engine

▸ Load balancer

▸ Replication

Page 30: Leveraging a distributed architecture to your advantage

HOW SOMETHING SIMPLE THINGS BECOMES VERY COMPLEX VERY QUICKLY

MORE ITEMS ADDED

▸ Caching

▸ Search engine

▸ Load balancer

▸ Replication

▸ Queues

Page 31: Leveraging a distributed architecture to your advantage

HOW SOMETHING SIMPLE THINGS BECOMES VERY COMPLEX VERY QUICKLY

MORE ITEMS ADDED

▸ Caching

▸ Search engine

▸ Load balancer

▸ Replication

▸ Queues

▸ Workers

Page 32: Leveraging a distributed architecture to your advantage

HOW SOMETHING SIMPLE THINGS BECOMES VERY COMPLEX VERY QUICKLY

MORE ITEMS ADDED

▸ Caching

▸ Search engine

▸ Load balancer

▸ Replication

▸ Queues

▸ Workers

▸ API’s

Page 33: Leveraging a distributed architecture to your advantage

HOW SOMETHING SIMPLE THINGS BECOMES VERY COMPLEX VERY QUICKLY

MORE ITEMS ADDED

▸ Caching

▸ Search engine

▸ Load balancer

▸ Replication

▸ Queues

▸ Workers

▸ API’s

▸ and even more things …

Page 34: Leveraging a distributed architecture to your advantage

PHP-FPM

NGINXShared FS

MariaDB

MariaDB

MariaDB

MongoDB

MongoDB

MongoDB

Redis Cache

Redis Cache

Redis Cache

ElasticSearch ElasticSearch

Varnish

RabbitMQ

PHP (workers)

PHP (workers)

PHP-FPM

NGINX

Page 35: Leveraging a distributed architecture to your advantage

EVENT SOURCING: GBC (MARCO PIVETTA)

MUST-SEE PRESENTATION

Page 36: Leveraging a distributed architecture to your advantage

MAKING CHOICES

Page 37: Leveraging a distributed architecture to your advantage
Page 38: Leveraging a distributed architecture to your advantage

ON PREM

Page 39: Leveraging a distributed architecture to your advantage

ON PREM

CLOUD

Page 40: Leveraging a distributed architecture to your advantage

ON PREM

HOSTED

CLOUD

Page 41: Leveraging a distributed architecture to your advantage

MOVE TO THE “CLOUD”, TRUST ME I’M A PROFESSIONAL!!!

Page 42: Leveraging a distributed architecture to your advantage
Page 43: Leveraging a distributed architecture to your advantage

Source: The Register 2015-09-20

Source: CBS News 2017-02-28

Source: Forbes 2014-11-18

Source: ZDNet 2016-09-15

Source: C|Net 2009-06-29

Source: The Register 2016-04-20

Source: InfoWorld 2013-03-22

Page 44: Leveraging a distributed architecture to your advantage
Page 45: Leveraging a distributed architecture to your advantage

THIS IS BAD!!!NO NEED TO SAY…

Page 46: Leveraging a distributed architecture to your advantage

SCALING MISTAKE #2: PUT ALL YOUR EGGS IN ONE BASKET.

Remember this!!!

TWEETABLE QUOTE

Page 47: Leveraging a distributed architecture to your advantage

STRATEGY IS KEY!

Page 48: Leveraging a distributed architecture to your advantage
Page 49: Leveraging a distributed architecture to your advantage

ONLINE?WHAT DID WE DO TO STAY

Page 50: Leveraging a distributed architecture to your advantage

CAN YOU LIVE WITH REDUCED CAPACITY BUT STAY ONLINE?

First question to clients

Page 51: Leveraging a distributed architecture to your advantage

Hosted / On Premise

Page 52: Leveraging a distributed architecture to your advantage

DynamoDB

EC2 EC2

Elas-csearchRDS-MySQLInstance

SQSQueueS3

Elas-cLoadBalancing

CloudFront

CloudSearch

West Europe

DynamoDB

EC2 EC2

Elas-csearchRDS-MySQLInstance

SQSQueueS3 CloudFront

CloudSearch

North Europe

DynamoDB

EC2 EC2

Elas-csearchRDS-MySQLInstance

SQSQueueS3 CloudFront

CloudSearch

South America

Page 53: Leveraging a distributed architecture to your advantage

West Europe North Europe South America

Page 54: Leveraging a distributed architecture to your advantage

DynamoDB

EC2 EC2

Elas-csearchRDS-MySQLInstance

SQSQueueS3

Elas-cLoadBalancing

CloudFront

CloudSearch

West Europe

DynamoDB

EC2 EC2

Elas-csearchRDS-MySQLInstance

SQSQueueS3 CloudFront

CloudSearch

North Europe South America

Page 55: Leveraging a distributed architecture to your advantage

DynamoDB

EC2 EC2

Elas-csearchRDS-MySQLInstance

SQSQueueS3

Elas-cLoadBalancing

CloudFront

CloudSearch

West Europe

DynamoDB

EC2 EC2

Elas-csearchRDS-MySQLInstance

SQSQueueS3 CloudFront

CloudSearch

North Europe South America

WARNING: THIS MEANS YOU NEED TO REPLICATE ALL TRANSACTIONS OVER BOTH CLOUD PROVIDERS!!! (COST X 2)

Page 56: Leveraging a distributed architecture to your advantage

SCALING MISTAKE #3: NOT READY FOR DISASTER

Remember this!!!

TWEETABLE QUOTE

Page 57: Leveraging a distributed architecture to your advantage

RESILIENCE TESTING

NETFLIX SIMIAN ARMY

▸ Chaos Monkey

▸ Chaos Gorilla

▸ Chaos Kong

▸ Janitor Monkey

▸ Doctor Monkey

▸ Compliance Monkey

▸ Latency Monkey

▸ Security Monkey

Page 58: Leveraging a distributed architecture to your advantage

ALWAYS PREPARE FOR THE WORST…

…so you’re ready when it happens.

Page 59: Leveraging a distributed architecture to your advantage

SCALING MISTAKE #4: DON’T AUTOMATE YOUR DEPLOYMENT PROCESSES

Remember this!!!

TWEETABLE QUOTE

Page 60: Leveraging a distributed architecture to your advantage

Build Feedback

Execute Delivery

SCMCommits SCM Change

Pollingtest

staging

production

Page 61: Leveraging a distributed architecture to your advantage

Unit tests Metrics

Provisioningnew target

Provisioningdatabases

Provisioningworkers

Integrationtests

Promotebranch

CI

Unit tests Metrics

Provisioningnew target

Provisioningdatabases

Provisioningworkers

Integrationtests

Promotebranch

CI

Page 62: Leveraging a distributed architecture to your advantage
Page 63: Leveraging a distributed architecture to your advantage
Page 64: Leveraging a distributed architecture to your advantage

AUTOMATE YOUR DEPLOYMENT PROCESS

So you can deploy multiple times a day.

Page 65: Leveraging a distributed architecture to your advantage

WHAT TO TAKE HOME FROM THIS TALK

RECAP

▸ Prepare you code to scale and distribute

▸ When online is important, scale over multiple hosting options

▸ Test your resilience for failure

▸ Automate your processes

▸ Build pipelines for all tasks

▸ Release with confidence

Page 66: Leveraging a distributed architecture to your advantage

in it2PROFESSIONAL PHP SERVICES

Michelangelo van DamZend Certified Engineer

[email protected] - www.in2it.be - T in2itvof - F in2itvof

Microsoft Azure Zend Framework Consulting

Quality Assurance & Disaster Recovery