my life with mongodb

59
My Life With MongoDB Mitch Pirtle, Miami MongoDB User Group February 2015

Upload: mitch-pirtle

Post on 16-Jul-2015

357 views

Category:

Technology


0 download

TRANSCRIPT

My Life With MongoDB

Mitch Pirtle, Miami MongoDB User Group February 2015

Before we get started.

Your MongoDB Fu?

Happy to show you how WiredTiger can be optimized

I got multiple apps in production with it

Currently using it in active development/projects

Hey I downloaded it at least, might even install it

Got donuts?

All righty then! Now a little about me.

Recovering Joomla! founder

Starting companies since 1995

Big on PHP, Node, Go, cloud tools, virtualization, containers

Big on developer workflow

Coach youth sports

Proud husband, dad

Don’t even THINK about touching my BBQ

Hey Ed, how much time do I got?

In the beginning…

We needed to store data

Data needed to be kept clean

Disk space was at a premium

Same for CPU and RAM

Efficiency was the most important factor

Life was good.

- Al Gore, supposedly

“Hey boys, check it out, the Internets!”

Number of concurrent users grew

Amount of data grew

Programming languages proliferated

Applications accessing our data proliferated

We all switched to Oracle or DB2

Hey what was that sound?

Arrival of the World Wide Web

Concurrent users jumped from 2 to 2,000,000

1,200 daily accesses turned into 20MM daily views

Throughput became the only critical element for your apps, and therefore your data

That smoking crater in the datacenter? Yeah, that was your DATABASE SERVER.

Something else was happening, too.

Programming languages

Perl, Python, Ruby, Java, PHP, and more

All used objects to represent structures

All were connected to relational databases

Which required…

The Object Relational Mapper (ORM)

Models represented “things”

Each model could be linked to other models

Has many, belongs to, is a member of…

It’s ok, we got this.

Fixes for rapid data growth

Stored procedures

Foreign keys

Triggers

Here comes the World Wide Web!

No, really, we got this.

Fixes for super mega whack-daddy growth

Sharding

Clustering

Multi-master

Read-only slaves

Replication

Flux Capacitors

Dilithium Crystals

Ok, we don’t got this.

Enter…

–Johnny Developer

“But it’s not ACID compliant! ZOMGWTFROFLBBQ!!1!”

“Somebody wanted acid?”

– Some Sucker On The Internet

“But somebody on YouTube said it would lose my data!”

You’re not losing me. I’m a fan favorite.

Main MongoDB goodness

Stores data as JSON documents

Sharding is built in

Clustering is built in

Slaves/replication is built in

Atomic writes, supports verified commits to disk

No JOINs

But how am I going to manage these queries that reach across umpteen different collections?

Denormalizing your data

Simple top-level schema

Logically driven

Atomic data

Your relational data looked like this.

Your document model looks like this.

Once again, with feeling.

Relational data.

Document data.

Relational data.

Document data.

Enough already!

User table, relational style

first_name: varchar(128)

last_name: varchar(128)

email: varchar(128)

password: varchar(128)

Seems simple enough. Right?

Not done yet.

address_id: int (refers to address.id)

gender_id: int (refers to gender.id)

account_type_id: int (refers to account types)

See? I got this all figured out.

I have two addresses.

create_user(user)

Ok first insert the users table

create_user(user)

Ok first insert the users table

No wait, first insert the address and get address.id

create_user(user)

Ok first insert the users table

No wait, first insert the address and get address.id

No, insert users record first, then the address, then update the users.address_id with the last_insert_id

EXAMPLE: User document

{ _id: “35b3d656-4e4b-41c0-85ab-23a9867a3e00”, first_name: “Mitch”, last_name: “Pirtle”, addresses: [ address_1: “123 Tondup Glacier”, address_2: “Second Yurt On The Left”, region: “Lhasa”, country: “Tibet” ]}

Yep, that’s all JSON.

Stumbling into MongoDB

Leave your 3NF data model behind

Atomicity is at the DOCUMENT LEVEL

There are different ways of doing things (e.g. findAndReplace)

“Scuse me while I whip this out.”

[CONSOLE]

Questions?

Thanks!

@mitchitized

http://about.me/mitchitized

http://www.slideshare.net/spacemonkeylabs

https://www.github.com/spacemonkey