SlideShare a Scribd company logo
[Anti]Patterns with NoSQL
         Luca Bonmassar
NoSQL vs. SQL
            NOSQL DAY ’11
NoSQL / NoAgenda

No specific NoSQL technologies (document, key/value, ...)
No specific NoSQL db features (sharding, replication, ...)
No specific ...
...


                                           NOSQL DAY ’11
Does it solve my problem?
                    NOSQL DAY ’11
Does it solve my problem?




                    NOSQL DAY ’11
Does it solve my problem?


But what is your problem?




                            NOSQL DAY ’11
Does it solve my problem?


But what is your problem?
NoSQL fragmentation (like NoCloud, NoJava,
NoMicrosoft, ...)



                                        NOSQL DAY ’11
[Anti]Patterns
The “dynamic” website

Data mapping

The Alien

The binary Alien

The SQLQueue

Overnormalized

Unpredictable tomorrow
                         NOSQL DAY ’11
Who am I?

Passionate about
technology
Favorite topics: Cloud,
Virtualization, NoSQL
Gamification fan! (or fun?)

                             NOSQL DAY ’11
The “dynamic” website
The “dynamic” website




                   NOSQL DAY ’11
The “dynamic” website

I have a website




                   NOSQL DAY ’11
The “dynamic” website

I have a website
Dynamic contents everywhere




                              NOSQL DAY ’11
The “dynamic” website

I have a website
Dynamic contents everywhere
High DB load


                              NOSQL DAY ’11
The “dynamic” website




                   NOSQL DAY ’11
The “dynamic” website




                   NOSQL DAY ’11
The “dynamic” website
               SELECT username                                                                                    SELECT COUNT(###) WHERE ...
              FROM users WHERE
                sessionid = ###
                                                           SELECT username
                                                          FROM users WHERE
                                                            sessionid = ###
SELECT COUNT("submissions"."puzzle_id")
FROM "submissions" WHERE (puzzle_id IS
  NOT NULL) AND (user_id IS NOT NULL)                                         SELECT COUNT(###) WHERE ...     SELECT COUNT(###) WHERE ...
         GROUP BY puzzle_id ...




         SELECT users.*, count(distinct puzzle_id) FROM
         submissions JOIN users on submissions.user_id                                                                SELECT * FROM submissions
          = users.id where submissions.current_state =                                                                        WHERE ...
                                                                                SELECT avatar.* FROM users
                         "succeeded" ...                                                WHERE ...




                                                                                                             NOSQL DAY ’11
The “dynamic” website
               SELECT username                                                                                    SELECT COUNT(###) WHERE ...
              FROM users WHERE
                sessionid = ###
                                                           SELECT username
                                                          FROM users WHERE
                                                            sessionid = ###
SELECT COUNT("submissions"."puzzle_id")
FROM "submissions" WHERE (puzzle_id IS
  NOT NULL) AND (user_id IS NOT NULL)                                         SELECT COUNT(###) WHERE ...     SELECT COUNT(###) WHERE ...
         GROUP BY puzzle_id ...




         SELECT users.*, count(distinct puzzle_id) FROM
         submissions JOIN users on submissions.user_id                                                                SELECT * FROM submissions
          = users.id where submissions.current_state =                                                                        WHERE ...
                                                                                SELECT avatar.* FROM users
                         "succeeded" ...                                                WHERE ...




                                                                                                             NOSQL DAY ’11
The “dynamic” website




                   NOSQL DAY ’11
The “dynamic” website
               SELECT username                                                                                    SELECT COUNT(###) WHERE ...
              FROM users WHERE
                sessionid = ###
                                                           SELECT username
                                                          FROM users WHERE
                                                            sessionid = ###
SELECT COUNT("submissions"."puzzle_id")
FROM "submissions" WHERE (puzzle_id IS
  NOT NULL) AND (user_id IS NOT NULL)                                         SELECT COUNT(###) WHERE ...     SELECT COUNT(###) WHERE ...
         GROUP BY puzzle_id ...




         SELECT users.*, count(distinct puzzle_id) FROM
         submissions JOIN users on submissions.user_id                                                                SELECT * FROM submissions
          = users.id where submissions.current_state =                                                                        WHERE ...
                                                                                SELECT avatar.* FROM users
                         "succeeded" ...                                                WHERE ...




                                                                                                             NOSQL DAY ’11
The “dynamic” website

Is it that dynamic?
Are there any data
structures that fit better
than relational?


                            NOSQL DAY ’11
Cache, Cache, Cache


Use Ad-Hoc Caching (e.g. Rails Caching)
SQL Table as cache



                                          NOSQL DAY ’11
SQL Table as Cache

When you use SQL Table as
Cache, a kitten somewhere
dies
Use Memcache,
MemcacheDB, Redis


                            NOSQL DAY ’11
Better tools?
                NOSQL DAY ’11
Rethink data structures
SELECT COUNT(*) ...
SELECT COUNT(*) ...
SELECT COUNT(*) ...


submitted++
passed++
failed++
                      NOSQL DAY ’11
Rethink data structures
SELECT *, count(distinct ...)
FROM submissions JOIN
users on ... where
submissions.current_state
= "succeeded" ...
List(5)
List.add / List.replace
                                NOSQL DAY ’11
Data mapping
Data mapping

An original idea: we need a newsfeed!
Users can comment on feed items
Users can reply to comments


                                        NOSQL DAY ’11
What the customer is looking for
                         NOSQL DAY ’11
What the developer is thinking about
                           NOSQL DAY ’11
But how to ...
Eureka!

The item has a feed_id and
a parent_id
You have now a navigable
SQL data structure!


                             NOSQL DAY ’11
Data mapping - alternatives

Do not try this at home! (or any office)
A document db can help
    { feed : 42, user : ‘luca.bonmassar’, data : ‘living the
   dream!’, comments : [{user : ‘jonny’ : ‘make sense!’ }] }


                                          NOSQL DAY ’11
The Alien
The Alien

A type of object stored in a relational database
No (or weak) relations with any other table
Stored in the db because the db == persistency


                                           NOSQL DAY ’11
User Settings

User preferences
user_id, data
Data as BLOB or TEXT


                       NOSQL DAY ’11
The Alien


The Alien is a key/value entity
Use a key/value storage to store it



                                      NOSQL DAY ’11
The binary Alien
The binary Alien

Like the Alien, but the payload is pure binary data
Common solution to store “small” images
Even worse: Base64 encoded binary


                                           NOSQL DAY ’11
The binary Alien

Move the binary Alien to a binary content provider
   S3 or Filesystem are good ones
Let the webserver access/serve them directly


                                          NOSQL DAY ’11
The SQLQueue
The SQLQueue

Distributed components need to exchange data
   Producers / Consumers
   Backlog of work to be completed
SQL database (== persistency) as persistent queue


                                         NOSQL DAY ’11
Mail delivery




                NOSQL DAY ’11
Mail delivery




                NOSQL DAY ’11
Mail delivery




                NOSQL DAY ’11
Mail delivery




                NOSQL DAY ’11
The SQLQueue


No “relations”, like the Alien
Simulating a Queue using AUTO_INCREMENT ids and
transactions



                                     NOSQL DAY ’11
SQLQueue

In some countries,
SQLQueue is considered a
crime against software
Use message queues
(Amazon SQS, MemcacheQ,
StormMQ, RabbitMQ, ... )

                           NOSQL DAY ’11
Overnormalized
Overnormalized




                 NOSQL DAY ’11
Overnormalized

The process of organizing data to minimize redundancy




                                        NOSQL DAY ’11
Overnormalized

The process of organizing data to minimize redundancy
A larger schema is broken into smaller ones




                                         NOSQL DAY ’11
Overnormalized

The process of organizing data to minimize redundancy
A larger schema is broken into smaller ones
   user_id, email




                                         NOSQL DAY ’11
Overnormalized

The process of organizing data to minimize redundancy
A larger schema is broken into smaller ones
   user_id, email
   user_id, phone_num


                                         NOSQL DAY ’11
Overnormalized

The process of organizing data to minimize redundancy
A larger schema is broken into smaller ones
   user_id, email
   user_id, phone_num
   user_id, badge

                                         NOSQL DAY ’11
Overnormalized

PRO:
  reduce redundancy
  less overhead
  each table scale separately


                                NOSQL DAY ’11
Overnormalized
Cons:




                 NOSQL DAY ’11
Overnormalized
Cons:




... JOIN... JOIN... JOIN... JOIN... JOIN... JOIN... JOIN...

                                               NOSQL DAY ’11
Overnormalized

Cache the normalized data
Denormalize / keep a replica of the denormalized view
Use document db or key/value storage for the replica



                                         NOSQL DAY ’11
Unpredictable tomorrow
Unpredictable tomorrow

You are now part of a new Agile(TM) project
You are Agile(TM), so:
   No complete specs
   No complete use cases


                                         NOSQL DAY ’11
How many wonderful things around me

A mobile App w/ internet backend
“Simple” use cases
   User can log in
   User can update their location
   User can get all the many wonderful things they have
   around themselves
                                         NOSQL DAY ’11
How many wonderful things around me


Data Model:
   User
   Places
Aliens!!! Aliens!!! Aliens!!!


                                NOSQL DAY ’11
...but sooner or later...
                    NOSQL DAY ’11
How many wonderful things around me

Users can send/receive friendship invitations
Users can import FB friends, Twitter followers
Users can interact with messages, pokes
Users can check-in into places
Users can share their checkins with friends
...
                                              NOSQL DAY ’11
Unpredictable tomorrow

No silver bullets
Mix technologies
   E.g. relational databases to handle relations
Migrations are painful, but always an option


                                          NOSQL DAY ’11
One more thing
Recap


Does it make sense with the relational paradigm?
Do I need a persistent storage or a relational database?



                                          NOSQL DAY ’11
Thanks! Any Questions?
                 NOSQL DAY ’11
Contacts

luca@coderloop.com
linkedin.com/in/lucabonmassar
twitter.com/lucabonmassar


joind.in/talk/view/2939

                                NOSQL DAY ’11

More Related Content

PPTX
Build your own entity with Drupal
PDF
JPA2 - a brief intro
PDF
4Developers 2018: Structuring React components (Bartłomiej Witczak)
PDF
Structuring React.js Components
PDF
Dependency Inversion and Dependency Injection in PHP
PDF
Drupal Entities - Emerging Patterns of Usage
PDF
Node Access in Drupal 7 (and Drupal 8)
KEY
Drupalcamp gent - Node access
Build your own entity with Drupal
JPA2 - a brief intro
4Developers 2018: Structuring React components (Bartłomiej Witczak)
Structuring React.js Components
Dependency Inversion and Dependency Injection in PHP
Drupal Entities - Emerging Patterns of Usage
Node Access in Drupal 7 (and Drupal 8)
Drupalcamp gent - Node access

What's hot (20)

PDF
GQL CheatSheet 1.1
PDF
Command-Oriented Architecture
PDF
GQL cheat sheet latest
PDF
Sql Antipatterns Strike Back
PPT
07 association of entities
PDF
hibernate
PDF
Sqlalchemy sqlの錬金術
PDF
Dojo >= 1.7 Kickstart
PPTX
Web Security - Hands-on
PPT
Introduction to hibernate
PPTX
Introduction to SQL Antipatterns
ZIP
OOCSS for Javascript pirates at jQueryPgh meetup
PPTX
Mule esb – connecting to ms sql db
PPT
JQuery New Evolution
PDF
Introduction to jOOQ
PDF
Advanced GORM - Performance, Customization and Monitoring
PDF
Functionality Focused Code Organization
PDF
SOLID Ruby SOLID Rails
PDF
Rails' Next Top Model
PDF
Sql alchemy bpstyle_4
GQL CheatSheet 1.1
Command-Oriented Architecture
GQL cheat sheet latest
Sql Antipatterns Strike Back
07 association of entities
hibernate
Sqlalchemy sqlの錬金術
Dojo >= 1.7 Kickstart
Web Security - Hands-on
Introduction to hibernate
Introduction to SQL Antipatterns
OOCSS for Javascript pirates at jQueryPgh meetup
Mule esb – connecting to ms sql db
JQuery New Evolution
Introduction to jOOQ
Advanced GORM - Performance, Customization and Monitoring
Functionality Focused Code Organization
SOLID Ruby SOLID Rails
Rails' Next Top Model
Sql alchemy bpstyle_4
Ad

Viewers also liked (18)

PDF
NoSQL and SQL Anti Patterns
PPTX
NoSQL vs SQL (by Dmitriy Beseda, JS developer and coach Binary Studio Academy)
PPT
SQL vs NoSQL
PDF
SQL vs NoSQL: 
проблема выбора
PDF
2017 - NoSQL Vorlesung Mosbach
PPTX
Getting Release Management Right for SQL Server
PPTX
Sql vs. NoSql
PDF
SQL vs. NoSQL Databases
PDF
Presto: Distributed SQL on Anything - Strata Hadoop 2017 San Jose, CA
PDF
MongoDB Performance Tuning
PPTX
NOSQL vs SQL
PPTX
Sql vs NoSQL
PDF
Multi-model database
PDF
Jeudis du Libre - MySQL comme Document Store
PDF
OLAP for Big Data (Druid vs Apache Kylin vs Apache Lens)
PDF
NOSQL Meets Relational - The MySQL Ecosystem Gains More Flexibility
PDF
NoSQL Now! NoSQL Architecture Patterns
PDF
Visual Design with Data
NoSQL and SQL Anti Patterns
NoSQL vs SQL (by Dmitriy Beseda, JS developer and coach Binary Studio Academy)
SQL vs NoSQL
SQL vs NoSQL: 
проблема выбора
2017 - NoSQL Vorlesung Mosbach
Getting Release Management Right for SQL Server
Sql vs. NoSql
SQL vs. NoSQL Databases
Presto: Distributed SQL on Anything - Strata Hadoop 2017 San Jose, CA
MongoDB Performance Tuning
NOSQL vs SQL
Sql vs NoSQL
Multi-model database
Jeudis du Libre - MySQL comme Document Store
OLAP for Big Data (Druid vs Apache Kylin vs Apache Lens)
NOSQL Meets Relational - The MySQL Ecosystem Gains More Flexibility
NoSQL Now! NoSQL Architecture Patterns
Visual Design with Data
Ad

Similar to Patterns / Antipatterns with NoSQL (20)

PDF
Introduction to Quill
PDF
2013-03-23 - NoSQL Spartakiade
PDF
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
PPT
JavaTalks: OOD principles
PDF
Django Multi-DB in Anger
PDF
Slides python elixir
PDF
Integrating SAP the Java EE Way - JBoss One Day talk 2012
PDF
Design of Remorseful
PDF
Automatically Assessing Code Understandability: How Far Are We?
PDF
Why no sql
PDF
Play framework
PDF
RxJava for Android - GDG DevFest Ukraine 2015
PDF
How to React Native
PDF
Connect.js - Exploring React.Native
PDF
AngularJs
PDF
Java e i database: da JDBC a JPA
PPTX
JSON SQL Injection and the Lessons Learned
PDF
Building a Mobile Data Platform with Cassandra - Apigee Under the Hood (Webcast)
PDF
Scaladroids: Developing Android Apps with Scala
Introduction to Quill
2013-03-23 - NoSQL Spartakiade
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
JavaTalks: OOD principles
Django Multi-DB in Anger
Slides python elixir
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Design of Remorseful
Automatically Assessing Code Understandability: How Far Are We?
Why no sql
Play framework
RxJava for Android - GDG DevFest Ukraine 2015
How to React Native
Connect.js - Exploring React.Native
AngularJs
Java e i database: da JDBC a JPA
JSON SQL Injection and the Lessons Learned
Building a Mobile Data Platform with Cassandra - Apigee Under the Hood (Webcast)
Scaladroids: Developing Android Apps with Scala

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
KodekX | Application Modernization Development
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation theory and applications.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
Digital-Transformation-Roadmap-for-Companies.pptx
KodekX | Application Modernization Development
“AI and Expert System Decision Support & Business Intelligence Systems”
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation_ Review paper, used for researhc scholars
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Spectroscopy.pptx food analysis technology
Encapsulation theory and applications.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Electronic commerce courselecture one. Pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release

Patterns / Antipatterns with NoSQL