17 Things Developers should know about Databases · You want instant durable replication over wide...

52
© 2019 Percona. 1 Peter Zaitsev 17 Things Developers should know about Databases CEO, Percona Nizhny Novgorod, Russia November 9th, 2019

Transcript of 17 Things Developers should know about Databases · You want instant durable replication over wide...

Page 1: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 1

Peter Zaitsev

17 Things Developers should know about Databases

CEO, PerconaNizhny Novgorod, Russia

November 9th, 2019

Page 2: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 2

Thank you!

Page 3: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 3

About Percona

Open Source Database Solutions Company

Support, Managed Services, Consulting, Training, Engineering

Focus on MySQL, MariaDB, MongoDB, PostgreSQL

Support Cloud DBaaS Variants on major clouds

Develop Database Software and Tools

Release Everything as 100% Free and Open Source

Page 4: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 4

5,000,000+ downloads 175,000+ downloads 4,500,000+ downloads

450,000+ downloads 2,000,000+ downloads 1,500,000+ downloads

Widely Deployed Open Source Software

Page 5: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 5

Freshly Released

Percona Distribution for PostgreSQL

Page 6: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 6

Who Are you ?

More Developer ?

More OPS ?

Page 7: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 7

Ops

Focused on Database Only

Generalist

Page 8: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 8

Programming Language

What Programming Languages does your

team use ?

Page 9: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 9

Devs vs Ops

Is there Separation between Devs and Ops in

your Organization ?

Page 10: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 10

Any Tension ?

Any Tension Between Devs and Ops ?

Page 11: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 11

Devs vs Ops Conflict

Devs

• Why is this stupid database always the problem.

• Why can’t it just work and work fast

Ops

• Why do not learn schema design

• Why do not you write optimized queries

• Why do not you think about capacity planning

Page 12: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 12

Database are Special Snowflakes

Production Database Changes are Risky and Costly

Often need special handling with Continuous Deployment

Page 13: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 13

Large Organizations

Ops vs Ops have conflict too

Page 14: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 14

Database Responsibility

Shared Responsibility for Ultimate Success

Page 15: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 15

Top Recommendations for Developers

Page 16: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 16

Learn Database Basics

You can’t build great database powered applications if you do not understand how databases work

Schema Design

Power of the Database Language

How Database Executes the Query

Page 17: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 17

Query Execution Diagram

Page 18: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 18

EXPLAIN

https://dev.mysql.com/doc/refman/8.0/en/execution-plan-information.html

Page 19: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 19

Visualizing PostgreSQL Plan with PEV

http://tatiyants.com/postgres-query-plan-visualization/

Page 20: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 20

Which Queries are Causing the Load

Page 21: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 21

Why Are they Causing this Load

Page 22: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 22

How to Improve their Performance

Page 23: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 23

Check out PMM

http://pmmdemo.percona.com

PMM v 2 is now GA

Page 24: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 24

How are Queries Executed ?

Single Threaded

Single Node

Distributed

Page 25: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 25

Indexes

Indexes are Must

Indexes are Expensive

Page 26: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 26

Capacity Planning

No Database can handle “unlimited scale”

Scalability is very application dependent

Trust Measurements more than Promises

Can be done or can be done Efficiently ?

Page 27: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 27

Vertical and Horizontal Scaling

Page 28: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 28

Scalable != Efficient

The Systems promoted as scalable can be less efficient

Hadoop, Cassandra, TiDB are great examples

By only the wrong thing you can get in trouble

Page 29: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 29

Throughput != Latency

If I tell you system can do 100.000 queries/sec

would you say it is fast ?

Page 30: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 30

Speed of Light Limitations

High Availability Design Choices

You want instant durable replication over wide geography or Performance ?

Understanding Difference between High Availability and Disaster Recovery protocols

Network Bandwidth is not the same as Latency

Page 31: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 31

Wide Area Networks

Tend not to be as stable as Local Area Networks (LAN)

Expect increased Jitter

Expect Short term unavailability

Page 32: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 32

Also Understand

Connections to the database are expensive

Especially if doing TLS Handshake

Query Latency Tends to Add Up

Especially on real network and not your laptop

Page 33: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 33

ORM (Object-Relational-Mapping)

Allows Developers to query the database without need to understand SQL

Can create SQL which is very inefficient

Learn SQL Generation “Hints”, Learn JPQL/HQL advanced features

Be ready to manually write SQL if there is no other choice

Page 34: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 34

Understanding Optimal Concurrency

Page 35: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 35

Embrace Queueing

Request Queueing is Normal

With requests coming at “Random Arrivals” some queueing will happen with any system scale

Should not happen to often or for very long

Queueing is “Cheaper” Close to the User

Page 36: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 36

Benefits of Connection Pooling

Avoiding Connection Overhead,

especially TLS/SSL

Avoiding using Excessive Number

of Database Connections

Multiplexing/Load Management

Page 37: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 37

Configuring Connection Pool

Default and Maximum Connection Pool Size

Scaling Parameters

Combined Connection Pool Max Size should be smaller than number of connections database can support

Waiting for free connection to become available is OK

Page 38: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 38

Scale Matters

Developing and Testing with Toy Database is risky

Queries Do not slow down linearly

The slowest query may slow down most rapidly

Page 39: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 39

Memory or Disk

Data Accessed in memory is much faster than on disk

It is true even with modern SSDs

SSD accesses data in large blocks, memory does not

Fitting data in Working Set

Page 40: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 40

Newer is not Always Faster

Upgrading to the new

Software/Hardware is not always faster

Test it outDefaults Change are

often to blame

Page 41: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 41

Upgrades are needed but not seamless

Major Database Upgrades often require application changes

Having Conversation on Application Lifecycle is a key

Page 42: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 42

Character Sets

Performance Impact

Pain to Change

Wrong Character Set can cause Data Loss

Page 43: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 43

Character Sets

https://per.co.na/MySQLCharsetImpact

Page 44: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 44

Less impact In MySQL 8

Page 45: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 45

Operational Overhead

Operations Take Time, Cost Money, Cause Overhead

10TB Database Backup ?

Adding The Index to Large Table ?

Page 46: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 46

Distributed Systems

10x+ More Complicated

Better High Availability

Many Failure Scenarios

Test how application performs

Page 47: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 47

Risks of Automation

Automation is Must

Mistakes can destroy

database at scale

Page 48: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 48

Security

Database is where the most sensitive data tends to live

Shared Devs and Ops Responsibility

Page 49: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 49

Law of Gravity

Shitty Application at scale will bring down any

Database

Page 50: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 50

What Else

What Would you Add ?

Page 51: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 51

Check Out http://per.co.na/careers

Page 52: 17 Things Developers should know about Databases · You want instant durable replication over wide geography or Performance ? Understanding Difference between High Availability and

© 2019 Percona. 52

Thank You!Twitter: @percona @peterzaitsev