common scalability practices that just...

39
Common scalability practices that just work Dino Esposito JetBrains dino.esposito@jetbrains.com @despos facebook.com/naa4e

Upload: others

Post on 27-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Common scalability

practices that just work

Dino Esposito

JetBrains

[email protected]

@despos

facebook.com/naa4e

Page 2: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Quest is …

Overcome many obstacles

Go through troubles, pain, exertion

A lot of trial-and-error

Usability & Scalability

A journey towards a symbolic goal

Page 3: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Scalability as teenage sex

Everyone talks about it

Nobody really knows how to do it

Everyone thinks everyone else is doing it

So everyone claims they are doing it...

Yes

YesMmm

NEED

Page 4: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Domain and app matching

No product or technology can magically make a

system scalable and usable.

Not because you save data to the cloud, your app

survives thousands of concurrent users.

Not because of HTML5 users will enjoy the application.

Page 5: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Scalability

System's ability to handle a growing number of

requests without incurring in significant

performance loss and failures.

Resiliency Fine-tuning

Page 6: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Scalability & Performance

Different attributes, but related

Sometimes, scalability and performance concerns

may even be in conflict and choices made to

improve scalability actually lower down actual

performance of individual calls.

Changing …

Page 7: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Scalability became a problem with the advent of web

Closed Open Open Closed

Page 8: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Queuing theory

You have a queue when the ratio at which requests

for a service are placed exceeds the time it takes to

fully serve a pending request.

It’s about the performance of a single task

It’s about expanding the system to perform more tasks

at the same time

Page 9: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Strategies

Page 10: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Ensure the system

Doesn’t crash at launch

Gives signs of degrading performance timely

Make sure you know the most common tools and

strategies to address scalability needs.

Page 11: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Vertical vs. Horizontal

Page 12: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Vertical

Norm for 20 years – so long as DB was central point

Doesn’t scale beyond a point

Front caching is a good way to do it

• Proxy servers with load balancing capabilities

• Working outside the core code of the application

• Squid, Varnish, Nginx

Page 13: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Real-world

Quite a few high traffic web are based on a classic

ASP.NET web site schema deployed to a web farm

• With several layers of cache on the forefront

• Airliners, news and media portals

Page 14: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Horizontal

Mostly an architectural point

Critical parts can be expanded without

• Damaging other parts

• Introducing inconsistencies / incongruent data

Page 15: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Horizontal

LOAD

BALANCING

MULTIPLE

INSTANCESDATA

SHARDING

Page 16: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Real-world

Cloud apps are probably the easiest and most effective

way to achieve forms of scalability today.

But, at the same time, you can have well responsive

apps without re-architecting for the cloud.

Page 17: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Common Practices

Page 18: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Operational Practice #1

Remove bottlenecks

• Convoluted queries

• Long initialization steps

• Inefficient algorithms

HIGH throughput

MEDIUM cost

TIME consuming

DELICATE

Page 19: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Operational Practice #2

Move “some” requests to other servers

• CDN for static files

• Geographically distributed sites

LOW throughput

LOW cost

Quick

Improves the user’s perception of the system

Page 20: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Operational Practice #3

Output Caching

• By param

• By locale

• By custom data

for example, multi-tenant sites

MEDIUM

throughput

LOW cost

Quick

MEDIUM risk

Page 21: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Operational Practice #4

Data Caching

• Problematic with farms

• Auto-updatable internal cache

• Use of distributed caches

Redis, ScaleOut, NCache

HIGH throughput

MEDIUM cost

Relatively Quick

DELICATE

Page 22: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Operational Practice #5

Proxy caching for example Varnish

• Installed in front of any web site

• Fully configurable

• Cache and load balancer in one

HIGH throughput

Relatively LOW

cost

Relatively Quick

Page 23: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

CDN vs. Proxy Caching

Not an either/or choice; often go together.

PROXY CACHING

CDN CDN CDN

Web site

Geographically

distributed

Page 24: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Architectural Practice #1

CQRS Architecture

Optimize stacks differently

HIGH throughput

HIGH cost

Time consuming

Page 25: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Presentation layer

Application layer

Infrastructure layer

Canonical layered architecture

Domain layer

Presentation layer

Application layer

Infrastructure layer

CQRS

Commands Queries

Domain layer

Data

access

+

DTO

Message-based business logic implementation

Page 26: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

BUSINESS

DOMAIN

Command

Context #1

Query

Context #1

Command

Context #2

Query

Context #2

Command

Context #3

Query

Context #3

CQRS Design

DDD Analysis

CONTEXT

#1

CONTEXT

#2

CONTEXT

#3

Requirements

Page 27: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Architectural Practice #2

Single-tier and stateless server

• One server

• No session state

• Quick and easy to duplicate

• Behind a load balancer

HIGH throughput

Low cost

Quick

Page 28: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

The point of the cloud

Page 29: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Architectural Practice #3

Cloud support

On-demand servers

Pay per use

Configure easily

No middleware costs

Better failure policies

Page 30: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

DISTRIBUTED CACHESERVERSERVER

SERVER

SERVER

DISTRIBUTED

CACHECACHE

PERSISTENT

Auto-update

internal cacheGlobal cache

Page 31: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Architectural Practice #4

Session state out of the server

• Client cookies if applicable

• Distributed cache

• Azure blob storage

HIGH throughput

MEDIUM cost

Relatively quick

Tricky

PS: Best option for ASP.NET is probably using the Redis-based

provider for out-of-process session state.

Page 32: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Architectural Practice #5

Be aware of NoSQL and polyglot persistence

• Relational is OK … until it works

• Sharding/growth of data

Azure SQL+ Many small tables <500GB each

+ No extra license costs

+ Zero TCO

+ HA automatically on

SQL Server in a VM+ Fewer large tables >500GB each

+ Reuse existing licenses

+ More machine resources

+ HA and management is your own

Page 33: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Case-studies

Page 34: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

StackOverflow

Top50 most trafficked web sites 500M page views in a month and growing

< 10 Visual Studio projects

100,000 lines of code

Nearly no unit tests: code coverage of 0.25%

Web projects based on ASP.NET MVC

Move fast and break things (that users don’t see)

Deploy 5 times a day

Page 35: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Caching is the secret weapon

5 levels of data caching

Network (i.e., CDN and browsers)

Server (ASP.NET cache)

Site (Redis)

SQL Server (1 terabyte of RAM)

Solid state disks

For more information: http://speakerdeck.com/sklivvz

Page 36: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Globo.com

Largest portal and ISP in South America45 million views per day 2x StackOverflow

1 Scrum master, 1 designer, 1 lead architect

TDD, peer programming, CI, 10 days sprints

WordPress with PHP

Python/Django for server-side code

Data storage is MySQL, MongoDB & Memcached

Reverse proxy caching

Page 37: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

Talking CMS that grow BIG

1. Your database grows really BIG

2. Monolithic code hard to cluster

3. Content generation become EXPENSIVE

4. Site slows DANGEROUSLY down

Page 38: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

My personal horror story

Presentation

MOST OF THE TIME … YOU DON’T HAVE SCALABILITY PROBLEMS.

YOUR CODE JUST SUCKS.

Application

Domain

InfrastructureHTTP facade

Presentation

Application

Domain

Infrastructure

SERVER

SERVER

Page 39: Common scalability practices that just worksddconf.com/brands/sdd/library/Common_Scalability_Practices.pdf · Not because of HTML5 users will enjoy the application. Scalability System's

FOLLOW

That’s All Folks!

facebook.com/naa4e

software2cents.wordpress.com

[email protected]

@despos