Best Design Practices A

73
http://42sql.com (c) Copyright 2008 Best Design Practices - Part A Building Scalable Enterprise Solutions Architecture, Performance, Scalability, Migration, Knowledge Transfer 1

description

At 42SQL we follow the “Scale 2 Success” (tm) approach covering Architecture, Availability, Scalability and Accountability. With this we are able to clearly provide a strategy towards building successful scalable enterprise solutions. For more information on how we may be able to help your organization with any performance and scalability needs, please use the Contact Form.

Transcript of Best Design Practices A

Page 1: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Building Scalable Enterprise SolutionsArchitecture, Performance, Scalability, Migration, Knowledge Transfer

1

Page 2: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Ronald BradfordPrincipal

42SQL

[email protected] 1.0 3.Aug..2008

Best Design Practices

For MySQL Architects, DBA’s and

Developers

2

Page 3: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Introduction

❖ Lots of information to discuss❖ Basic principles❖ Rules

3

Page 4: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Agenda

❖ Architecture❖ Availability❖ Scalability❖ Accountability

4

Page 5: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Architecture

❖ Toolset❖ The performance equation❖ Data integrity

ARCHITECTURE

5

Page 6: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Your Toolset

❖ Generics are inefficient❖ different RDBMS is not enough ❖ You have chosen MySQL

ARCHITECTURE

6

Page 7: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Your MySQL Toolset

❖ Maximize MySQL strengths❖ Scale out / HA Options❖ Different Storage Engines❖ Query Cache - Both good and bad

ARCHITECTURE

7

Page 8: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Your MySQL Toolset

❖ Minimize MySQL weaknesses❖ No Online Alter❖ Backup Strategies❖ Instrumentation

ARCHITECTURE

8

Page 9: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Your MySQL Toolset

❖ Connector/J❖ Supports read/write splitting❖ Supports read balancing across slaves❖ Supports failover

❖ Connection.setReadOnly(true | false);

http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-replication-connection.html

Example

ARCHITECTURE

9

Page 10: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Your Toolset

RTFMARCHITECTUREManual: http://dev.mysql.com/doc

Book: High Performance MySQL - 2nd Edition

10

Page 11: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

The performance equation

Disk = Memory = Performance

❖ Every single byte counts❖ Average saving of 25% - 30%❖ Better 60% ‏❖ Best 78%

ARCHITECTURE

11

Page 12: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

The performance equation

❖ Favorite signs of poor design in data types❖ INT(1)‏❖ BIGINT AUTO_INCREMENT❖ no UNSIGNED used❖ DECIMAL(31,0)‏

ARCHITECTURE

12

Page 13: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Data integrity

❖ MySQL historically has been very lax❖ Warnings (e.g. Truncations) are rarely every caught

❖ sql_mode=strict_all_tables

ARCHITECTURE

http://ronaldbradford.com/blog/why-sql_mode-is-important-part-i-2008-07-17/13

Page 14: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Data integrity

❖ With Schema❖ NOT NULL❖ ENUM❖ UNSIGNED

ARCHITECTURE

http://ronaldbradford.com/blog/why-sql_mode-is-important-part-i-2008-07-17/14

Page 15: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Data integrity

❖ Storage Engines❖ Always design for transactions❖ Always use transactions❖ Use a transactional storage engine

ARCHITECTURE

15

Page 16: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

From Top 20 Design Tips

1. Know your technology tools

2. Know your disk footprint3. Choose your numeric data type

4. Other data type efficiencies5. Application data type efficiencies

6. NOT NULL

7. Know about character sets8. When VARCHAR is bad

9. Be Wary of TEXT/BLOB10. Know every SQL Statement

11. Monitor Every SQL Statement

12. The impact of Indexes13. Index types for design

14. Minimizing internal MySQL Processing15. Transactions

16. Data Integrity is key

17. Leveraging the Query Cache18. Create Object appropriately

19. Naming Standards20. Testing, Testing, Testing

http://ronaldbradford.com/presentations.htm#200804

ARCHITECTURE

16

Page 17: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Further Discussion (Part B)

❖ How to design for caching at multiple levels❖ Cloud computing considerations (MySQL/ Non MySQL)

❖ Supporting 3rd party applications (REST/SOAP/XMMP)

❖ CAP Theory (Consistency, Availability, Partition)

❖ Balancing design with agile approaches❖ Hardware requirements (Disk, Memory, Network, CPU)

❖ Managing different Read/Write environments

ARCHITECTURE

17

Page 18: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Site presence

❖ What happens when your site is:❖ Unavailable❖ Under load❖ Something is broken❖ Undergoing maintenance❖ Somebody elseʼs mistake (e.g. Data Center)

AVAILABILITY

18

Page 19: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

19

Page 20: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

20

Page 21: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Firefox Download day - Example 1 21

Page 22: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Firefox Download day - Example 222

Page 23: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

23

Page 24: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

24

Page 25: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Minimum Ideals

❖ Static version of site❖ Support for Read Only & Write Enabled❖ Support for components being unavailable

AVAILABILITY

25

Page 26: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Further Discussion (Part B)

❖ What is no downtime and how to achieve it?❖ Tracking referrer through site navigation❖ What is the minimum MySQL configuration?❖ The strengths and weaknesses of MySQL Topologies

AVAILABILITY

26

Page 27: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scalability

❖ Successful scaling is?

SCALABILITY

27

Page 28: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scalability

❖ Successful scaling is?

Scale Out not Scale Up

SCALABILITY

28

Page 29: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scalability

❖ To scale out is to?

SCALABILITY

29

Page 30: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scalability

❖ To scale out is to?

Shard

SCALABILITY

30

Page 31: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale out

❖ The art of Sharding is?❖ A one day seminar (ask me for more)

SCALABILITY

31

Page 32: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale out

❖ A database table consists of❖ Columns❖ Rows

SCALABILITY

32

Page 33: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

TABLE col1 col2 col3 col4 col5 col6 col7row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Columns

33

Page 34: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

TABLE col1 col2 col3 col4 col5 col6 col7row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Columns

34

Page 35: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

TABLE col1 col2 col3 col4 col5 col6 col7row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Columns

35

Page 36: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

TABLE col1 col2 col3 col4 col5 col6 col7row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Rows

36

Page 37: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

TABLE col1 col2 col3 col4 col5 col6 col7row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Rows

37

Page 38: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

TABLE col1 col2 col3 col4 col5 col6 col7row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Rows

38

Page 39: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale out

❖ A database consists of❖ Tables❖ Table Rows

SCALABILITY

39

Page 40: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5

Tables

40

Page 41: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5

Tables

41

Page 42: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5

Tables

42

Page 43: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Table Rows

43

Page 44: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Table Rows

44

Page 45: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Table Rows

45

Page 46: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale out

❖ Partitioning is?❖ Grouping like rows in a table together❖ e.g.

❖ By Date❖ By Local❖ By parent grouping

SCALABILITY

46

Page 47: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

TABLE col1 col2 col3 col4 col5 col6 col7row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Partition

47

Page 48: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

TABLE col1 col2 col3 col4 col5 col6 col7row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Partition

48

Page 49: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

TABLE col1 col2 col3 col4 col5 col6 col7row1row2row3row4row5row6row7row8row9

row10row11row12row13row14

Partition

49

Page 50: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale out

❖ Sharding is?❖ Grouping like tables together❖ optionally partition subsets of rows

SCALABILITY

50

Page 51: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5

Table Group

51

Page 52: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5

Table Group

52

Page 53: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5

Table Group

53

Page 54: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5

Table Group + Rows

54

Page 55: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5

Table Group + Rows

55

Page 56: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5

Table Group + Rows

56

Page 57: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale outSCALABILITY

table1 table2 table3 table4 table5

Table Group + Rows

57

Page 58: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale out

❖ How do you group tables?

SCALABILITY

58

Page 59: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Scale out

❖ How do you group tables?

Thatʼs the secret

SCALABILITY

59

Page 60: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Further Discussion (Part B)

❖ The partition key is the key❖ Poor examples of sharding❖ The theory of ideal partition key❖ Balancing and re balancing

SCALABILITY

60

Page 61: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Further Discussion (Part B)

❖ Master/Master does not solve scalability❖ Store data in a database, donʼt always retrieve

from the database❖ Cache at multiple layers

SCALABILITY

61

Page 62: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Accountability

❖ The rule of everything ❖ You should look at your logs

ACCOUNTABILITY

62

Page 63: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

The Rule of Everything

❖ Everythingʼs are ❖ Monitor❖ Measure❖ Graph❖ Automate

ACCOUNTABILITY

63

Page 64: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Easy Information to know

❖ Know your error logs❖ System, Database, Application, RAID

❖ Seen degraded RAID multiple times ***❖ donʼt ignore errors (such as Innodb)

ACCOUNTABILITY

64

Page 65: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Further Discussion (Part B)

❖ Testability❖ Donʼt think of testing as to know your software works,

testing should be to break your software ❖ Know every single SQL Statement❖ Your application should have detailed metrics

ACCOUNTABILITY

65

Page 66: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Executive Summary

Architecture

❖ Learn and know MySQL specifics❖ Disk = Memory = Performance❖ Integrity is important, but how important is

consistency?

ARCHITECTURE

66

Page 67: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Executive Summary

Availability

❖ Test your site response under error cases❖ Disaster is inevitable. Donʼt wait for it❖ Try testing unavailability first ❖ Write failing test cases for your website first

AVAILABILITY

67

Page 68: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Executive Summary

Scalability

❖ Think low cost commodity hardware❖ like general cloud computing architecture

❖ Understanding sharding from day 1❖ XMPP

SCALABILITY

68

Page 69: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Executive Summary

Accountability

❖ Donʼt let users tell you when things donʼt work❖ You need numbers to predicate failure❖ You have to have history for trending❖ Log, Review & Monitor all SQL

ACCOUNTABILITY

69

Page 70: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Whatʼs next

❖ Any key point could be an hour discussion

❖ What 3 points are best topics for audience?

70

Page 71: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Looking forward

A word on cloud computing

❖ Donʼt put all your eggs in one basket❖ Keep your important data close

71

Page 72: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Professional Help is Available

❖ 2 decades Expertise & Experience ❖ Architecture, Design, Performance & Scalability

❖ 9 years in MySQL

ronaldbradford.com42sql.com

72

Page 73: Best Design Practices A

http://42sql.com(c) Copyright 2008

Best Design Practices - Part A

Building Scalable Enterprise SolutionsArchitecture, Performance, Scalability, Migration, Knowledge Transfer

73