Top Banner
54
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Big and Fat: Using MongoDB with Deep and Diverse Data
Page 2: Big and Fat: Using MongoDB with Deep and Diverse Data

Big and FatUsing MongoDB with deep and diverse datasets:

A case study

Page 3: Big and Fat: Using MongoDB with Deep and Diverse Data

About me

• My name is Jeremy McAnally

• “Software architect” at Intridea

• Write a lot of books, OSS, etc.

• http://github.com/jm

• http://twitter.com/jm

• http://railsupgradehandbook.com

• http://wickhamhousebrand.com

Page 4: Big and Fat: Using MongoDB with Deep and Diverse Data

MongoDB analytics just likemom used to make.

http://mongobase.com

Page 5: Big and Fat: Using MongoDB with Deep and Diverse Data

Preface

The Application™

Page 6: Big and Fat: Using MongoDB with Deep and Diverse Data
Page 7: Big and Fat: Using MongoDB with Deep and Diverse Data
Page 8: Big and Fat: Using MongoDB with Deep and Diverse Data

Disclaimer

We moved to (mostly) sql.

Page 9: Big and Fat: Using MongoDB with Deep and Diverse Data
Page 10: Big and Fat: Using MongoDB with Deep and Diverse Data
Page 11: Big and Fat: Using MongoDB with Deep and Diverse Data

YAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVE

YAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVE

YAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVE

YAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVE

YAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVE

YAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVE

YAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVE

YAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVEYAK SHAVE

Page 12: Big and Fat: Using MongoDB with Deep and Diverse Data

Lesson 1

Abstraction is a double-edged sword.

Page 13: Big and Fat: Using MongoDB with Deep and Diverse Data

Abstract away!Talking to all data (no matter the source) the same way will

keep you sane.

Page 14: Big and Fat: Using MongoDB with Deep and Diverse Data

!"#$"%&%'()*+,,*!#$(-#.#/!0#12)3+345%6%789'%!"#$":2;

!"#$"-#</=%>?%@!@

%%A?"0"%&%>B-/?CC#/0D?E1FA?"0"F;-GDE>1,!"#$HD>%&I%!JFD>FK;

%%L%J---K

%%/?MM#E0"%&%>B-/?CC#/0D?E1F/?MM#E0"F;-GDE>12NO=#$#2%&I%2"!M

10=D"-<>MDEH/?!E0P%0=D"-M?>#$<0?$H/?!E0;%&&%Q2;

#E>

Page 15: Big and Fat: Using MongoDB with Deep and Diverse Data

!"#$"%&%R"#$-<CC

!"#$"-#</=%>?%@!@

%%A?"0"%&%S?"0-GDE>1,!"#$HD>%&I%!-D>;

%%L%J---K

%%/?MM#E0"%&%4?MM#E0-O=#$#12"!M10=D"-<>MDEH/?!E0P%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%0=D"-M?>#$<0?$H/?!E0;%&&%Q2;

#E>

Page 16: Big and Fat: Using MongoDB with Deep and Diverse Data

!"#$"%&%R"#$-<CC

!"#$"-#</=%>?%@!@

%%A?"0"%&%S?"0-GDE>1,!"#$HD>%&I%!-D>;

%%L%J---K

%%/?MM#E0"%&%4?MM#E0-OD0=HGDT#H0=DEU"

#E>

Page 17: Big and Fat: Using MongoDB with Deep and Diverse Data

...but wait!MongoDB has a lot of features that will perform better and be

less (and often better) code.

Page 18: Big and Fat: Using MongoDB with Deep and Diverse Data

A=<$M</D"0"%&%VW

S<0D#E0-<CC-#</=%>?%@A<0D#E0@

%%A<0D#E0-A$#"/$DA0D?E"-#</=%>?%@A$#"/$DA0D?E@

%%%%A=<$M</D"0"JA$#"/DA0D?E-E<M#K%@@&%X

%%%%A=<$M</D"0"JA$#"/DA0D?E-E<M#K%Y&%Z

%%#E>

#E>

Page 19: Big and Fat: Using MongoDB with Deep and Diverse Data

A=<$M</D"0"%&%VW

S<0D#E0-<CC-#</=%>?%@A<0D#E0@

%%A<0D#E0-A$#"/$DA0D?E"-#</=%>?%@A$#"/$DA0D?E@

%%%%A=<$M</D"0"JA$#"/DA0D?E-E<M#K%@@&%X

%%%%A=<$M</D"0"JA$#"/DA0D?E-E<M#K%Y&%Z

%%#E>

#E>SLOW AS

CRAP

Page 20: Big and Fat: Using MongoDB with Deep and Diverse Data

M<A%&%2G!E/0D?E1;V

%%%%0=D"-A$#"/$DA0D?E"-G?$3</=1

%%%%%%G!E/0D?E1A;%V%

%%%%%%%%#MD01A-E<M#P%V%/?!E0%,%Z%W;:

%%%%W;W2%

%%

$#>!/#%&%2G!E/0D?E1[P%T;%V

%%T<$%E!MB#$%&%X:

%%G?$%T-G?$3</=1G!E/0D?E1;%V

%%%%E!MB#$%Y&%TJDK-/?!E0:

%%W;:

%%$#0!$E%V%/?!E0%,%E!MB#$%W:%

W2%

%%

A=<$M"%&%\A<0D#E0"-M<AH$#>!/#1M<AP%$#>!/#;

Page 21: Big and Fat: Using MongoDB with Deep and Diverse Data

M<A%&%2G!E/0D?E1;V

%%%%0=D"-A$#"/$DA0D?E"-G?$3</=1

%%%%%%G!E/0D?E1A;%V%

%%%%%%%%#MD01A-E<M#P%V%/?!E0%,%Z%W;:

%%%%W;W2%

%%

$#>!/#%&%2G!E/0D?E1[P%T;%V

%%T<$%E!MB#$%&%X:

%%G?$%T-G?$3</=1G!E/0D?E1;%V

%%%%E!MB#$%Y&%TJDK-/?!E0:

%%W;:

%%$#0!$E%V%/?!E0%,%E!MB#$%W:%

W2%

%%

A=<$M"%&%\A<0D#E0"-M<AH$#>!/#1M<AP%$#>!/#;

Page 22: Big and Fat: Using MongoDB with Deep and Diverse Data

Lesson 2

Schema design matters.

Page 23: Big and Fat: Using MongoDB with Deep and Diverse Data

Lesson 2

Schema design matters.DATA MODEL

Page 24: Big and Fat: Using MongoDB with Deep and Diverse Data

Embedding works.

Embedding documents is a smart decision in a lot of cases.

Page 25: Big and Fat: Using MongoDB with Deep and Diverse Data

)3+345%6%789'%A<0D#E0"%]^383%D>&_Z_:

)3+345%6%789'%A$#"/$DA0D?E"%]^383%A<0D#E0HD>&_Z_:

)3+345%6%789'%<AA?DE0M#E0"%]^383%A<0D#E0HD>&_Z_:

)3+345%6%789'%/?E0</0"%]^383%A<0D#E0HD>&_Z_:

)3+345%6%789'%/C<DM"%]^383%A<0D#E0HD>&_Z_:

-

-

-

Page 26: Big and Fat: Using MongoDB with Deep and Diverse Data

...but watch it.You can also hit a ton of

performance and design issues.

Page 27: Big and Fat: Using MongoDB with Deep and Diverse Data
Page 28: Big and Fat: Using MongoDB with Deep and Diverse Data
Page 29: Big and Fat: Using MongoDB with Deep and Diverse Data

OUR GIANT DOCUMENT

Mongo’s Pre-Allocated Space

Page 30: Big and Fat: Using MongoDB with Deep and Diverse Data

Patient

Pharmacy

“Reference”Pharmacy

Search, listing, etc.

Page 31: Big and Fat: Using MongoDB with Deep and Diverse Data

Lesson 3

Don’t go nuts.

Page 32: Big and Fat: Using MongoDB with Deep and Diverse Data

Schemaless is fun!

Having schemaless data has its own battery of advantages.

Page 33: Big and Fat: Using MongoDB with Deep and Diverse Data

Schemaless Joy

Page 34: Big and Fat: Using MongoDB with Deep and Diverse Data

Schemaless Joy

• Transforming data models is a delight

Page 35: Big and Fat: Using MongoDB with Deep and Diverse Data

Schemaless Joy

• Transforming data models is a delight

• Formless data isn’t awkward

Page 36: Big and Fat: Using MongoDB with Deep and Diverse Data

Schemaless Joy

• Transforming data models is a delight

• Formless data isn’t awkward

• Arbitrary embedding is awesome

Page 37: Big and Fat: Using MongoDB with Deep and Diverse Data

Schemaless Joy

• Transforming data models is a delight

• Formless data isn’t awkward

• Arbitrary embedding is awesome

• Building to work with schemaless data can lead to some really powerful app concepts

Page 38: Big and Fat: Using MongoDB with Deep and Diverse Data

...but be wary.Going nuts will create

headaches for you.

Page 39: Big and Fat: Using MongoDB with Deep and Diverse Data

Schemaless Pain

Page 40: Big and Fat: Using MongoDB with Deep and Diverse Data

Schemaless Pain

• Weird app behavior

Page 41: Big and Fat: Using MongoDB with Deep and Diverse Data

Schemaless Pain

• Weird app behavior

• Huge, long-running data transformations

Page 42: Big and Fat: Using MongoDB with Deep and Diverse Data

Schemaless Pain

• Weird app behavior

• Huge, long-running data transformations

• Annoying data transforms for development env’s

Page 43: Big and Fat: Using MongoDB with Deep and Diverse Data

Schemaless Pain

• Weird app behavior

• Huge, long-running data transformations

• Annoying data transforms for development env’s

• Difficult to version data models

Page 44: Big and Fat: Using MongoDB with Deep and Diverse Data

Lesson 4

Dig deep.

Page 45: Big and Fat: Using MongoDB with Deep and Diverse Data

I%>B-$!E4?MM<E>1V2"#$T#$)0<0!"2%,%ZW;

V

% 2T#$"D?E2%,%2Z-`-a2P

% 2!A0DM#2%,%bcP

% 2C?/<C5DM#2%,%25=!%d?T%Ze%_XZX%XZ,`b,ae%

f'5gXQXX%13)5;2P

% 2UC?B<C+?/[2%,%V

% % 20?0<C5DM#2%,%bcXXQ_bXP

% % 2C?/[5DM#2%,%Zh`X`XP

% % 2$<0D?2%,%X-XXZeZ_eZchh_bXbXhc_

% WP

% 2M#M2%,%V

% % 2BD0"2%,%c`P

% % 2$#"D>#E02%,%_P

% % 2TD$0!<C2%,%_abcP

% % 2"!AA?$0#>2%,%0$!#P

% % 2M<AA#>2%,%X

% WP

% 2/?EE#/0D?E"2%,%V

% % 2/!$$#E02%,%ZP

% % 2<T<DC<BC#2%,%Zbbbb

% WP

% 2#.0$<HDEG?2%,%V

% % 2E?0#2%,%2GD#C>"%T<$(%B(%AC<0G?$M2

% WP

% 2DE>#.4?!E0#$"2%,%V

% % 2B0$##2%,%V

% % % 2<//#""#"2%,%XP

% % % 2=D0"2%,%XP

% % % 2MD""#"2%,%XP

% % % 2$#"#0"2%,%XP

% % % 2MD""8<0D?2%,%X

% % W

% WP

% 2B</[U$?!E>7C!"=DEU2%,%V

% % 2GC!"=#"2%,%ZP

% % 20?0<CHM"2%,%XP

% % 2<T#$<U#HM"2%,%XP

% % 2C<"0HM"2%,%XP

% % 2C<"0HGDED"=#>2%,%25=!%d?T%Ze%_XZX%

XZ,`b,X_%f'5gXQXX%13)5;2

% WP

% 2?A/?!E0#$"2%,%V

% % 2DE"#$02%,%XP

% % 2i!#$(2%,%ZP

% % 2!A><0#2%,%XP

% % 2>#C#0#2%,%XP

% % 2U#0M?$#2%,%XP

% % 2/?MM<E>2%,%a

% WP

% 2<""#$0"2%,%V

% % 2$#U!C<$2%,%XP

% % 2O<$EDEU2%,%XP

% % 2M"U2%,%XP

% % 2!"#$2%,%XP

% % 2$?CC?T#$"2%,%X

% WP

% 2?[2%,%Z

W

Page 46: Big and Fat: Using MongoDB with Deep and Diverse Data

2?A/?!E0#$"2%,%V

%%2DE"#$02%,%XP

%%2i!#$(2%,%ZP

%%2!A><0#2%,%XP

%%2>#C#0#2%,%XP

%%2U#0M?$#2%,%XP

%%2/?MM<E>2%,%a

W

Page 47: Big and Fat: Using MongoDB with Deep and Diverse Data

2/?EE#/0D?E"2%,%V

%%2/!$$#E02%,%ZP

%%2<T<DC<BC#2%,%Zbbbb

W

Page 48: Big and Fat: Using MongoDB with Deep and Diverse Data

j#$#M(g'/kE<CC("g'</l??[gS$?,m%n#$#M(M/<E<CC(N%M?EU?"0<0

/?EE#/0#>%0?,%Z_h-X-X-Z

DE"#$0o"%i!#$(o"%!A><0#o"%>#C#0#o"%U#0M?$#o"%/?MM<E>o"%M<AA#>%%T"Dp#%%%%$#"%q%C?/[#>%q%D>.%MD""%%/?EE%%%%%0DM#%

%%%%%%%X%%%%%%%X%%%%%%%%X%%%%%%%%X%%%%%%%%%X%%%%%%%%%Z%%%%%%X%%%_abc%%%%%%a%%%%%%%%X%%%%%%%%%%X%%%%%Z%XZ,Qa,a_%

%%%%%%%X%%%%%%%X%%%%%%%%X%%%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/?$#%,%Z-X%W2%P%2DE+?/[2%,%Z%W

%%%%%%%%%%K

W

Page 52: Big and Fat: Using MongoDB with Deep and Diverse Data

I%>B-?AC?U-NM<DE-GDE>1;

V%20"2%,%V%202%,%Z_bXXcaQccXXXP%2D2%,%Z%WP%2?A2%,%2D2P%2E"2%,%2MDEU-G??2P%2?2%,%V%2HD>2%,%9Bn#/0r>12`/#`/#/#<BBZBcQZQeXXXXXZ2;P%20=DEU2%,%_%W%W

V%20"2%,%V%202%,%Z_bXXcaQcbXXXP%2D2%,%Z%WP%2?A2%,%2E2P%2E"2%,%22P%2?2%,%V%W%W

V%20"2%,%V%202%,%Z_bXXcaQhbXXXP%2D2%,%Z%WP%2?A2%,%2E2P%2E"2%,%22P%2?2%,%V%W%W

V%20"2%,%V%202%,%Z_bXXcaQeZXXXP%2D2%,%Z%WP%2?A2%,%2D2P%2E"2%,%2MDEU-G??2P%2?2%,%V%2HD>2%,%9Bn#/0r>12`/#`/#>><BBZBcQZQeXXXXX_2;P%20=DEU2%,%_%W%W

V%20"2%,%V%202%,%Z_bXXcaQeZXXXP%2D2%,%_%WP%2?A2%,%2D2P%2E"2%,%2MDEU-G??2P%2?2%,%V%2HD>2%,%9Bn#/0r>12`/#`/#>><BBZBcQZQeXXXXXa2;P%20=DEU2%,%_%W%W

Page 53: Big and Fat: Using MongoDB with Deep and Diverse Data

V%20"2%,%

%%V%202%,%Z_bXXcaQccXXXP%

%%%%2D2%,%Z%

%%WP%

%%2?A2%,%2D2P%

%%2E"2%,%2MDEU-G??2P%

%%2?2%,%V%

%%%%%2HD>2%,%9Bn#/0r>12`/#`/#/#<BBZBcQZQeXXXXXZ2;P%

%%%%%2GD#C>2%,%_%

%%W%

W

Page 54: Big and Fat: Using MongoDB with Deep and Diverse Data

That’s all I got.

Questions?