43
Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn / <[email protected]> May 14th, 2016

Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn / May 14th, 2016

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution of Web Application ArchitecturePHPDay Italy

Kore Nordmann / @koredn / <[email protected]>May 14th, 2016

Page 2: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Hi, I’m Kore

Page 3: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Architecture

Page 4: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 5: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Too many visitors

CC BY 2.0 Scott Cresswell – https://flic.kr/p/knkntv

Page 6: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 7: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 8: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Lessons Learned: Load Balancing

I Works because of HTTP & PHPI HTTP is LCoDC$SSI PHP is build for shared-nothing

I Round Robin works bestI Sticky sessions will overload certain servers

Page 9: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Non sticky session– how?

CC BY 2.0 DJ Bustos – https://flic.kr/p/rLfXoR

Page 10: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 11: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Lessons Learned: Non-Sticky Session

I Put session on memcached / RedisI Mostly trivial because of existing extensions

Page 12: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Where to put thestatic data?

CC BY 2.0 Richard – https://flic.kr/p/joASfQ

Page 13: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 14: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Lessons Learned: Static Files

I NFS will eventually lead to dead locksI . . . still seems the most popular solution around.

I Multiple domains can hurt performance (TCP slow start)I Using dedicated CDN providers can help

I Content locality

Page 15: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Database serverstoo slow…

CC BY 2.0 super awesome – https://flic.kr/p/75LH5i

Page 16: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 17: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Lessons Learned: Replicate Database

I Master Slave Replication is fairly easy to set upI Obviously only scales READsI WRITEs are usually not your first problem

Page 18: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Database serverstoo expensive…

CC BY-SA-NC 3.0 Kore Nordmann

Page 19: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 20: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Lessons Learned: Cache With Memcache

I Cache all the things in memoryI Cache entitiesI Cache collectionsI Full page cache

I Cache invalidationThere are three hard things in Computer Science:Cache invalidation and off by one errors.

I Cache dependency calculationI The paging problem

Page 21: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Too many writes

CC BY 2.0 Drew Coffman – https://flic.kr/p/8kvbSL

Page 22: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 23: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Sharding

I Split tables across multiplenodes

I Vertical shardingI Shard by consistent

hashingI Horizontal sharding

product

user

Page 24: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Lessons Learned: Sharding

I Shard by tableI . . . or even shard by consistent hash per entity

I No referential integrity checkingI Queries are limited to sharding solutionI Schema updates across multiple shards are fun

Page 25: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Setup too complex

CC BY 2.0 KellarW – https://flic.kr/p/rqJYiZ

Page 26: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 27: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Lessons Learned: NoSQL

I Usually solves one problem really well:I ShardingI Multi-Master-ReplicationI Cross-shard queries

I Usually omits:I SQLI Referential Integrity

I . . . we lost all relevant features fromRelational Database Management Systemsanyways. . .

Page 28: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Keeping data consistentacross multiple nodes

CC BY 2.0 Beraldo Leal – https://flic.kr/p/56UqaR

Page 29: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Data Consistency Across Nodes

?

✓????

Page 30: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Eventual Consistency

Truth ClientUpdater /Replicator

Last Revision?

<hash>

Get Updates Since <hash>

{update, revision}[]{update, revision}[]

null

Revisions MUSTincrement

strictly monotonic

Revisions MUST NOTbe stored if anupdate fails.

Page 31: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Lessons Learned: Data Consistency

I Embrace Eventual ConsistencyI Compaction is hardI Data migrations are hard

Page 32: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Business wants toquery data

CC BY 2.0 anton petukhov – https://flic.kr/p/rCGQp6

Page 33: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 34: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Lessons Learned: Map-Reduce

I Execute queries on distributed databasesI New query language to learn

I Your developers write analysis scripts, instead of the businessanalysts writing slow SQL queries

Page 35: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

How to orchestrate?

CC BY 2.0 Frederik Magle Music – https://flic.kr/p/bGW2Pv

Page 36: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 37: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Lessons Learned: Queues

I Queues can ensure data is processed asynchronouslyI Data consistency must be ensured even when pushing into

queuesI Following the data flow of an action can be “tricky”

I Used to distribute data between systems

Page 38: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Evolution

Page 39: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Microservices

Apply Seperation of Concerns on service level to allowfor seperate teams & technologies per concern.

I Microservices can simplify things:I Choose optimal technology stack per team & concern

I Microservices will also complicate things:I Automated deployment is a mustI Service orchestration is still a problemI Service downtimes and latency must be handled gracefully

(Eventual Consistency)

I Big DataTM will stay a problemI Sensible services are often not micro any more. . .

Page 40: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Lessons Learned (subjective)

I Boring technology choices will often work bestI Just start & stay with LAMP?

I Only bring in shiny new technologies with careI There are enough reasons to eventually do that, though

Page 41: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

The Hipster Says:

*

* Except you evaluated it as the correct solution for your case

Page 42: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

Copyright Qafoo GmbH; All Rights Reservedtalks.qafoo.com

Conclusion

I There are many developers, documentation & experience forboring technologies

I Evaluate before adding new technologies (ATAM)I Do not jump on every bandwagon – this includes

microservicesI Data Consistency accross nodes is hard &

important

Page 43: Evolution of Web Application Architecture - PHPDay Italy · Evolution of Web Application Architecture PHPDay Italy Kore Nordmann / @koredn /  May 14th, 2016

https://joind.in/talk/3152e