SlideShare una empresa de Scribd logo
1 de 74
Descargar para leer sin conexión
How Shutl Delivers Even Faster Using Neo4j
Sam Phillips andVolker Pacher	

@samsworldofno @vpacher
Volker Pacher
Sam Phillips
Graphs at Shutl
• Graph databases are awesome	

• We’ve seen lots of the talks about modelling	

• But querying is important too	

• So let’s talk about querying too!
Show of hands
• Who has used graph databases before?	

• Who has used Neo4j before?
Shutl
ECOMMERCE IS QUICK & CONVENIENT
PAYPAL FOR AWESOME DELIVERY
Branded, super quick delivery that people trust, embedded in merchant websites
A B
Only cost effective means to deliver 10+ miles but slow and unpredictable
HUB & SPOKE
POINTTO POINT
Fast and predictable but cost prohibitive over longer distances
A
B
HUB & SPOKE
97% Courier, Express & Parcel Market
POINT TO POINT
3% Courier, Express & Parcel Market
+7,500 more!
Shutl generates a quote from
each relevant carrier within
platform
Optimum picked based 	

on price & quality rating
SHOP
$$
$$$
$
$$
$
$$
On checkout, delivery sent via API into
chosen carrier’s transportation system
Courier collects from nearest
store and delivers to shopper
SHOP
$$
SHOP
Delivery status updated in
real-time, performance
compared against SLA &
carrier quality rating updated
Better performing carriers
get more deliveries & can
demand higher prices
Track your order online…
FEEDBACK
Quality paramount since we are motivated by LTV of shopper
Shutl sends feedback email to consumer seconds after they have received
delivery asking to rate qualitative aspects of experience
Feedback streamed unedited to shutl.com/feedback & facebook
FEEDBACK
FEEDBACK
FEEDBACK
FEEDBACK
COMPANYSHUTL IS NOW AN
Version One
Ruby 1.8, Rails 2.3 and MySQL
• Well-known tale: built quickly, worked slowly, tough to maintain	

• Getting a quote for an hour time-slot took over 4 seconds
Here is the Shutl price calendar
To generate this inV1, the merchant site would have had to call Shutl to get
available slots (2 seconds)
Here is the Shutl price calendar
To generate this inV1, the merchant site would have had to call Shutl to get
available slots (2 seconds)
Then, they would have to call Shutl to generate a quote for each slot - for
two days of store opening, that’s 20+ slots
So, that’s 2 + (20 x 4) seconds, 1:22 to generate the data for this calendar
InV1, this UX could never have happened.
V2
• Broke app into services	

• Services focused around functions like quoting, booking, and
giving feedback	

• Key goal for the project was improving the speed of the quoting
operation, which is where we used graph databases
V2
V1
V2
• Quoting for 20 windows down
from 82000 ms to 800 ms	

• Code complexity much
reduced
A large part of the success of our rewrite was
down to the graph database.
What is a graph anyway?
a collection of vertices (nodes) 	

connected by edges (relationships)
a simple graph
a short history
Leonard Euler
the seven bridges of Königsberg (1735)!
the seven bridges of Königsberg (1735)
Euler walk
each node has an even degree
no Euler walk
all nodes have an odd degree
directed graph
each relationship has a direction 	

(or one start node and one end node)
property graph
Person	

name: Sam
nodes contain properties (key, value)	

relationships have a type and are always directed	

relationships can contain properties too
Person	

name:Volker
:friends
Person	

name: Megan
:knows	

since: 2005
Company	

name: eBay
:friends
:works_for
:works_for
The Case for Graph Databases
relationships are explicit stored
additive domain modelling
whiteboard friendly
traversals of relationships are easy and very fast
DB performance remains relatively constant as
queries are localised to its portion of the graph.
O(1) for same query
a graph is its own index (constant query performance)
the case for Neo4j
standalone or embedded in jvm
ruby/jruby
ruby libraries - neo4j gem by Andreas Ronge
(https://github.com/andreasronge/neo4j)
cypher
the neotech guys are awesome
Querying the graph: Cypher
declarative query language specific to neo4j	

easy to learn and intuitive	

use specific patterns to query for (something that looks like ‘this’)	

inspired partly by SQL (WHERE and ORDER BY) and SPARQL (pattern matching)	

focuses on what to query for and not how to query for it	

switch from a mySQl world is made easier by the use of cypher instead of having to learn
a traversal framework straight away
START: Starting points in the graph, obtained via index lookups or by element IDs.	

MATCH: The graph pattern to match, bound to the starting points in START.	

WHERE: Filtering criteria.	

RETURN: What to return.	

CREATE: Creates nodes and relationships.	

DELETE: Removes nodes, relationships and properties.	

SET: Set values to properties.	

FOREACH: Performs updating actions once per element in a list.	

WITH: Divides a query into multiple, distinct parts	

cypher clauses
START: Starting points in the graph, obtained via index lookups or by element IDs.	

MATCH: The graph pattern to match, bound to the starting points in START.	

WHERE: Filtering criteria.	

RETURN: What to return.	

CREATE: Creates nodes and relationships.	

DELETE: Removes nodes, relationships and properties.	

SET: Set values to properties.	

FOREACH: Performs updating actions once per element in a list.	

WITH: Divides a query into multiple, distinct parts
an example
Person	

name: Sam
Person	

name:Volker
:friends
Person	

name: Megan
:knows	

since: 2005
Company	

name: eBay
:friends
:works_for
:works_for
Person	

name: Jim
:friends
Company	

name: neotech
:works_for
find all the companies my friends work for
MATCH (person{ name:’Volker’ }) -[:friends]	
- (person) - [:works_for]-> company	
RETURN company	
Person	

name: Sam
Person	

name:Volker
:friends
Person	

name: Megan
:knows	

since: 2005
Company	

name: eBay
:friends
:works_for
:works_for
Person	

name: Jim
:friends
Company	

name: neotech
:works_for
find all the companies my friend’s friends work for
MATCH (person{ name:’Volker’ }) -
[:friends*2..2]-(person) - [:works_for]
-> company	
RETURN company	
Person	

name: Sam
Person	

name:Volker
:friends
Person	

name: Megan
:knows	

since: 2005
Company	

name: eBay
:friends
:works_for
:works_for
Person	

name: Jim
:friends
Company	

name: neotech
:works_for
find all my friends who work for neotech
MATCH (person{ name:’Volker’ }) -[:friends]	
-(friends) - [:works_for]-> company	
WHERE company.name = ‘neotech’	
RETURN friends	
Person	

name: Sam
Person	

name:Volker
:friends
Person	

name: Megan
:knows	

since: 2005
Company	

name: eBay
:friends
:works_for
:works_for
Person	

name: Jim
:friends
Company	

name: neotech
:works_for
a good place to try it out:
!
http://console.neo4j.org/	

!
http://gist.neo4j.org/
coverage example
Locality	

id = california
Locality	

id = marin_county
Locality	

id = 94901
:contains
Store	

id = ebay_store
:located
:contains
Locality	

id = 94903
Locality	

id = 94902
:contains :contains
:operates Carrier	

id = carrier_2
Carrier	

id = carrier_1
:operates :operates
MATCH (store{ id:’ebay_store’ }) -[:located]	
-> (locality) <- [:operates]- carrier	
RETURN carrier	
the query
Locality	

id = 94902
Locality	

id = california
Locality	

id = marin_county
Locality	

id = 94901
:contains
Store	

id = ebay_store
:located
:contains
Locality	

id = 94903
:contains :contains
Carrier	

id = carrier_1
:operates :operates
MATCH (store{ id:’ebay_store’ }) -[:located]	
-> () <- [:contains*0..2] - (locality) 	
<- [:operates]- carrier	
RETURN carrier	
the query
Locality	

id = california
Locality	

id = marin_county
Locality	

id = 94901
:contains
Store	

id = ebay_store
:located
:contains
Locality	

id = 94903
Locality	

id = 94902
:contains :contains
:operates Carrier	

id = carrier_2
Carrier	

id = carrier_1
:operates :operates
SELECT * FROM carriers	

LEFT JOIN locations ON carrier.location_id = location.id 	

LEFT JOIN stores ON stores.location_id = carrier.location_id 	

WHERE stores.name = ‘ebay_store’
SELECT * FROM carriers	

LEFT JOIN locations ON carrier.location_id = location.id OR
carrier.location_id = location.parent_id 	

LEFT JOIN stores ON stores.location_id = carrier.location_id 	

WHERE stores.name = ‘ebay_store’
?
MATCH (store{ id:’ebay_store’ }) -[:located]	
-> () <- [:contains*0..2] - (locality) 	
<- [:operates]- carrier	
RETURN carrier
root (0)
Year: 2013
Month: 05 Month: 01
:year_2015
:month_01:month_05
:year_2014
Year: 2015
Month: 06
:month_06
Day: 24 Day: 25
:day_24 :day_25
Day: 26
:day_26
Event 1 Event 2 Event 3
:happens :happens :happens :happens
representing dates/times
find all events on a specific day
START root=node(0)	
MATCH root - [:year_2014] -> () -[:month_05] -> ()- [:day_24] -> () -
[:happens] -> event 	
RETURN event	 root (0)
Year: 2013
Month: 05 Month: 01
:year_2015
:month_01:month_05
:year_2014
Year: 2015
Month: 06
:month_06
Day: 24 Day: 25
:day_24 :day_25
Day: 26
:day_26
Event 1 Event 2 Event 3
:happens :happens :happens :happens
all together
Locality	

id = california
Locality	

id = marin_county
Locality	

id = 94901
:contains
Store	

id = ebay_store
:located
:contains
Carrier	

id = carrier_1
:operates
root (0)
Year: 2013
Month: 05
:month_05
:year_2014
Day: 24
:day_24
hour 09
hour 10
:hour_09
:hour_10
hour 11 :hour_11
:available {premium: 1}
:available {premium: 1.5}
MATCH (store{ id:’ebay_store’ }) -[:located]	
-> (locality) <- [:operates]- carrier - 	
[available:available] -> 	
() <- [:hour_10] - () <- [:day_24] - 	
() <- [:month_05] - () <- [:year_2014] - ()	
RETURN carrier, available.premium as premium	
all together
Locality	

id = california
Locality	

id = marin_county
Locality	

id = 94901
:contains
Store	

id = ebay_store
:located
:contains
Carrier	

id = carrier_1
:operates
root (0)
Year: 2013
Month: 05
:month_05
:year_2014
Day: 24
:day_24
hour 09
hour 10
:hour_09
:hour_10
hour 11 :hour_11
:available {premium: 1}
:available {premium: 1.5}
Other graph uses
• Recommendation engines
• Organisational analysis
• Graphing your infrastructure
• There was a learning curve in switching from a relational
mentality to a graph one
• Tooling not as mature as in the relational world
• No out of the box solution for db migrations
• Seeding an embedded database was unfamiliar
Some gotchas
• Setting up scenarios for tests was tedious
• Built our own tool based on the geoff syntax developed by Nigel Small
• Geoff allows modelling of graphs in textual form and provides an
interface to insert them into an existing graph
(A) {“name”: “Alice”}
(B) {“name”: “Bob”}
(A) -[:KNOWS] -> (B)
•We created a Ruby dsl for modelling a graph and inserting it into the db
that works with factory_girl
• Open source - https://github.com/shutl/geoff
Testing was a challenge
Wrap Up
• Neo4j and graph theory enabled Shutl to
achieve big performance increases in its
most important operation - calculating
delivery prices
• It’s a new tool based on tested theory, and
cypher is the first language that allows you to
query graphs in a declarative way (like SQL)
• Tooling and adoption is immature but getting
better all the time
Thank you!
!
Any questions?
Sam Phillips
Head of Engineering	

!
@samsworldofno	

http://samsworldofno.com	

sam@shutl.com
Volker Pacher
Senior Developer	

!
@vpacher	

https://github.com/vpacher	

volker@shutl.com

Más contenido relacionado

Destacado

Conferencia de Negocio Emgoldex Costa Rica
Conferencia de Negocio Emgoldex Costa RicaConferencia de Negocio Emgoldex Costa Rica
Conferencia de Negocio Emgoldex Costa Rica
Randall Santamaria
 
Alimentacion medicinal1jorgevaleraperu
Alimentacion medicinal1jorgevaleraperuAlimentacion medicinal1jorgevaleraperu
Alimentacion medicinal1jorgevaleraperu
JORGEHERBO
 
EKOMAK INDUSTRIAL COMPRESSORS
EKOMAK INDUSTRIAL COMPRESSORSEKOMAK INDUSTRIAL COMPRESSORS
EKOMAK INDUSTRIAL COMPRESSORS
Beler Bekdogan
 
OTT, IPTV, Web TV, Internet TV Solution
OTT, IPTV, Web TV, Internet TV SolutionOTT, IPTV, Web TV, Internet TV Solution
OTT, IPTV, Web TV, Internet TV Solution
robybaruch
 
AKQA Sky Installation CD User Flow
AKQA Sky Installation CD User FlowAKQA Sky Installation CD User Flow
AKQA Sky Installation CD User Flow
Adeeb Khan
 
El toro. Ignacio Linares 5º B
El toro. Ignacio Linares 5º BEl toro. Ignacio Linares 5º B
El toro. Ignacio Linares 5º B
Antonia
 
Berta velasco martinez 47259 assignsubmission_file_madrid 2016
Berta velasco martinez 47259 assignsubmission_file_madrid 2016Berta velasco martinez 47259 assignsubmission_file_madrid 2016
Berta velasco martinez 47259 assignsubmission_file_madrid 2016
Iescanet
 

Destacado (20)

Is the “Cooperative Life Cycle” Framework Relevant for Rural Africa?
Is the “Cooperative Life Cycle” Framework Relevant for Rural Africa?Is the “Cooperative Life Cycle” Framework Relevant for Rural Africa?
Is the “Cooperative Life Cycle” Framework Relevant for Rural Africa?
 
Diario Resumen 20161102
Diario Resumen 20161102Diario Resumen 20161102
Diario Resumen 20161102
 
Modelo REC / Reframing-Enlighten-Crusading (proyecto piloto)
Modelo REC / Reframing-Enlighten-Crusading (proyecto piloto)Modelo REC / Reframing-Enlighten-Crusading (proyecto piloto)
Modelo REC / Reframing-Enlighten-Crusading (proyecto piloto)
 
Sessió 3: Whatsapp per a pimes i emprenedors
Sessió 3: Whatsapp per a pimes i emprenedorsSessió 3: Whatsapp per a pimes i emprenedors
Sessió 3: Whatsapp per a pimes i emprenedors
 
Conferencia de Negocio Emgoldex Costa Rica
Conferencia de Negocio Emgoldex Costa RicaConferencia de Negocio Emgoldex Costa Rica
Conferencia de Negocio Emgoldex Costa Rica
 
Ingrid machado
Ingrid machadoIngrid machado
Ingrid machado
 
Alimentacion medicinal1jorgevaleraperu
Alimentacion medicinal1jorgevaleraperuAlimentacion medicinal1jorgevaleraperu
Alimentacion medicinal1jorgevaleraperu
 
Parasha nº 18
Parasha nº 18Parasha nº 18
Parasha nº 18
 
EKOMAK INDUSTRIAL COMPRESSORS
EKOMAK INDUSTRIAL COMPRESSORSEKOMAK INDUSTRIAL COMPRESSORS
EKOMAK INDUSTRIAL COMPRESSORS
 
OTT, IPTV, Web TV, Internet TV Solution
OTT, IPTV, Web TV, Internet TV SolutionOTT, IPTV, Web TV, Internet TV Solution
OTT, IPTV, Web TV, Internet TV Solution
 
Catálogo le bon acheteur s. coop.
Catálogo   le bon acheteur s. coop.Catálogo   le bon acheteur s. coop.
Catálogo le bon acheteur s. coop.
 
Pelacur mengajar sesama pelacur 2
Pelacur mengajar sesama pelacur 2Pelacur mengajar sesama pelacur 2
Pelacur mengajar sesama pelacur 2
 
MarketInvoice's £250 million celebration
MarketInvoice's £250 million celebrationMarketInvoice's £250 million celebration
MarketInvoice's £250 million celebration
 
AKQA Sky Installation CD User Flow
AKQA Sky Installation CD User FlowAKQA Sky Installation CD User Flow
AKQA Sky Installation CD User Flow
 
How The Top 500 Internet Retailers Collect Email Sign-ups (2016) [250ok]
How The Top 500 Internet Retailers Collect Email Sign-ups (2016) [250ok]How The Top 500 Internet Retailers Collect Email Sign-ups (2016) [250ok]
How The Top 500 Internet Retailers Collect Email Sign-ups (2016) [250ok]
 
El toro. Ignacio Linares 5º B
El toro. Ignacio Linares 5º BEl toro. Ignacio Linares 5º B
El toro. Ignacio Linares 5º B
 
Projeto site cosmopolit@n
Projeto site cosmopolit@nProjeto site cosmopolit@n
Projeto site cosmopolit@n
 
Berta velasco martinez 47259 assignsubmission_file_madrid 2016
Berta velasco martinez 47259 assignsubmission_file_madrid 2016Berta velasco martinez 47259 assignsubmission_file_madrid 2016
Berta velasco martinez 47259 assignsubmission_file_madrid 2016
 
Ruta de la Yerba - Investigación de Mercados
Ruta de la Yerba -  Investigación de MercadosRuta de la Yerba -  Investigación de Mercados
Ruta de la Yerba - Investigación de Mercados
 
Exposicion
ExposicionExposicion
Exposicion
 

Similar a QCon 2014 - How Shutl delivers even faster with Neo4j

Graphs fun vjug2
Graphs fun vjug2Graphs fun vjug2
Graphs fun vjug2
Neo4j
 

Similar a QCon 2014 - How Shutl delivers even faster with Neo4j (20)

Building Applications with a Graph Database
Building Applications with a Graph DatabaseBuilding Applications with a Graph Database
Building Applications with a Graph Database
 
GraphConnect 2014 SF: How eBay and Shutl Deliver Even Faster Using Neo4j
GraphConnect 2014 SF: How eBay and Shutl Deliver Even Faster Using Neo4jGraphConnect 2014 SF: How eBay and Shutl Deliver Even Faster Using Neo4j
GraphConnect 2014 SF: How eBay and Shutl Deliver Even Faster Using Neo4j
 
Neo4j Aura on AWS: The Customer Choice for Graph Databases
Neo4j Aura on AWS: The Customer Choice for Graph DatabasesNeo4j Aura on AWS: The Customer Choice for Graph Databases
Neo4j Aura on AWS: The Customer Choice for Graph Databases
 
Introduction to Domain-Driven Design in Ruby on Rails
Introduction to Domain-Driven Design in Ruby on RailsIntroduction to Domain-Driven Design in Ruby on Rails
Introduction to Domain-Driven Design in Ruby on Rails
 
There and Back Again, A Developer's Tale
There and Back Again, A Developer's TaleThere and Back Again, A Developer's Tale
There and Back Again, A Developer's Tale
 
Introduction to Neo4j and .Net
Introduction to Neo4j and .NetIntroduction to Neo4j and .Net
Introduction to Neo4j and .Net
 
Angularjs
AngularjsAngularjs
Angularjs
 
ql.io at NodePDX
ql.io at NodePDXql.io at NodePDX
ql.io at NodePDX
 
Graphs fun vjug2
Graphs fun vjug2Graphs fun vjug2
Graphs fun vjug2
 
Application Frameworks an Experience Report
Application Frameworks an Experience ReportApplication Frameworks an Experience Report
Application Frameworks an Experience Report
 
Neo4j: Import and Data Modelling
Neo4j: Import and Data ModellingNeo4j: Import and Data Modelling
Neo4j: Import and Data Modelling
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
 
Use dependency injection to get Hadoop *out* of your application code
Use dependency injection to get Hadoop *out* of your application codeUse dependency injection to get Hadoop *out* of your application code
Use dependency injection to get Hadoop *out* of your application code
 
How to leverage Kafka data streams with Neo4j
How to leverage Kafka data streams with Neo4jHow to leverage Kafka data streams with Neo4j
How to leverage Kafka data streams with Neo4j
 
_Python Ireland Meetup - Serverless ML - Dowling.pdf
_Python Ireland Meetup - Serverless ML - Dowling.pdf_Python Ireland Meetup - Serverless ML - Dowling.pdf
_Python Ireland Meetup - Serverless ML - Dowling.pdf
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
 
Relational Database to Apache Spark (and sometimes back again)
Relational Database to Apache Spark (and sometimes back again)Relational Database to Apache Spark (and sometimes back again)
Relational Database to Apache Spark (and sometimes back again)
 
How Concur uses Big Data to get you to Tableau Conference On Time
How Concur uses Big Data to get you to Tableau Conference On TimeHow Concur uses Big Data to get you to Tableau Conference On Time
How Concur uses Big Data to get you to Tableau Conference On Time
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

QCon 2014 - How Shutl delivers even faster with Neo4j

  • 1. How Shutl Delivers Even Faster Using Neo4j Sam Phillips andVolker Pacher @samsworldofno @vpacher
  • 3. Graphs at Shutl • Graph databases are awesome • We’ve seen lots of the talks about modelling • But querying is important too • So let’s talk about querying too!
  • 4. Show of hands • Who has used graph databases before? • Who has used Neo4j before?
  • 6. ECOMMERCE IS QUICK & CONVENIENT
  • 7. PAYPAL FOR AWESOME DELIVERY Branded, super quick delivery that people trust, embedded in merchant websites
  • 8. A B Only cost effective means to deliver 10+ miles but slow and unpredictable HUB & SPOKE POINTTO POINT Fast and predictable but cost prohibitive over longer distances A B
  • 9. HUB & SPOKE 97% Courier, Express & Parcel Market
  • 10. POINT TO POINT 3% Courier, Express & Parcel Market +7,500 more!
  • 11.
  • 12. Shutl generates a quote from each relevant carrier within platform Optimum picked based on price & quality rating SHOP $$ $$$ $ $$ $ $$
  • 13. On checkout, delivery sent via API into chosen carrier’s transportation system Courier collects from nearest store and delivers to shopper SHOP $$ SHOP
  • 14. Delivery status updated in real-time, performance compared against SLA & carrier quality rating updated Better performing carriers get more deliveries & can demand higher prices
  • 15. Track your order online…
  • 16. FEEDBACK Quality paramount since we are motivated by LTV of shopper Shutl sends feedback email to consumer seconds after they have received delivery asking to rate qualitative aspects of experience Feedback streamed unedited to shutl.com/feedback & facebook
  • 21.
  • 23. Version One Ruby 1.8, Rails 2.3 and MySQL • Well-known tale: built quickly, worked slowly, tough to maintain • Getting a quote for an hour time-slot took over 4 seconds
  • 24. Here is the Shutl price calendar To generate this inV1, the merchant site would have had to call Shutl to get available slots (2 seconds)
  • 25. Here is the Shutl price calendar To generate this inV1, the merchant site would have had to call Shutl to get available slots (2 seconds) Then, they would have to call Shutl to generate a quote for each slot - for two days of store opening, that’s 20+ slots So, that’s 2 + (20 x 4) seconds, 1:22 to generate the data for this calendar InV1, this UX could never have happened.
  • 26. V2
  • 27. • Broke app into services • Services focused around functions like quoting, booking, and giving feedback • Key goal for the project was improving the speed of the quoting operation, which is where we used graph databases V2
  • 28. V1 V2 • Quoting for 20 windows down from 82000 ms to 800 ms • Code complexity much reduced
  • 29. A large part of the success of our rewrite was down to the graph database.
  • 30. What is a graph anyway?
  • 31.
  • 32. a collection of vertices (nodes) connected by edges (relationships) a simple graph
  • 33. a short history Leonard Euler the seven bridges of Königsberg (1735)!
  • 34. the seven bridges of Königsberg (1735)
  • 35. Euler walk each node has an even degree
  • 36. no Euler walk all nodes have an odd degree
  • 37. directed graph each relationship has a direction (or one start node and one end node)
  • 38. property graph Person name: Sam nodes contain properties (key, value) relationships have a type and are always directed relationships can contain properties too Person name:Volker :friends Person name: Megan :knows since: 2005 Company name: eBay :friends :works_for :works_for
  • 39. The Case for Graph Databases
  • 43. traversals of relationships are easy and very fast
  • 44. DB performance remains relatively constant as queries are localised to its portion of the graph. O(1) for same query
  • 45. a graph is its own index (constant query performance)
  • 46. the case for Neo4j
  • 49. ruby libraries - neo4j gem by Andreas Ronge (https://github.com/andreasronge/neo4j)
  • 51. the neotech guys are awesome
  • 52. Querying the graph: Cypher declarative query language specific to neo4j easy to learn and intuitive use specific patterns to query for (something that looks like ‘this’) inspired partly by SQL (WHERE and ORDER BY) and SPARQL (pattern matching) focuses on what to query for and not how to query for it switch from a mySQl world is made easier by the use of cypher instead of having to learn a traversal framework straight away
  • 53. START: Starting points in the graph, obtained via index lookups or by element IDs. MATCH: The graph pattern to match, bound to the starting points in START. WHERE: Filtering criteria. RETURN: What to return. CREATE: Creates nodes and relationships. DELETE: Removes nodes, relationships and properties. SET: Set values to properties. FOREACH: Performs updating actions once per element in a list. WITH: Divides a query into multiple, distinct parts cypher clauses START: Starting points in the graph, obtained via index lookups or by element IDs. MATCH: The graph pattern to match, bound to the starting points in START. WHERE: Filtering criteria. RETURN: What to return. CREATE: Creates nodes and relationships. DELETE: Removes nodes, relationships and properties. SET: Set values to properties. FOREACH: Performs updating actions once per element in a list. WITH: Divides a query into multiple, distinct parts
  • 54. an example Person name: Sam Person name:Volker :friends Person name: Megan :knows since: 2005 Company name: eBay :friends :works_for :works_for Person name: Jim :friends Company name: neotech :works_for
  • 55. find all the companies my friends work for MATCH (person{ name:’Volker’ }) -[:friends] - (person) - [:works_for]-> company RETURN company Person name: Sam Person name:Volker :friends Person name: Megan :knows since: 2005 Company name: eBay :friends :works_for :works_for Person name: Jim :friends Company name: neotech :works_for
  • 56. find all the companies my friend’s friends work for MATCH (person{ name:’Volker’ }) - [:friends*2..2]-(person) - [:works_for] -> company RETURN company Person name: Sam Person name:Volker :friends Person name: Megan :knows since: 2005 Company name: eBay :friends :works_for :works_for Person name: Jim :friends Company name: neotech :works_for
  • 57. find all my friends who work for neotech MATCH (person{ name:’Volker’ }) -[:friends] -(friends) - [:works_for]-> company WHERE company.name = ‘neotech’ RETURN friends Person name: Sam Person name:Volker :friends Person name: Megan :knows since: 2005 Company name: eBay :friends :works_for :works_for Person name: Jim :friends Company name: neotech :works_for
  • 58. a good place to try it out: ! http://console.neo4j.org/ ! http://gist.neo4j.org/
  • 59. coverage example Locality id = california Locality id = marin_county Locality id = 94901 :contains Store id = ebay_store :located :contains Locality id = 94903 Locality id = 94902 :contains :contains :operates Carrier id = carrier_2 Carrier id = carrier_1 :operates :operates
  • 60. MATCH (store{ id:’ebay_store’ }) -[:located] -> (locality) <- [:operates]- carrier RETURN carrier the query Locality id = 94902 Locality id = california Locality id = marin_county Locality id = 94901 :contains Store id = ebay_store :located :contains Locality id = 94903 :contains :contains Carrier id = carrier_1 :operates :operates
  • 61. MATCH (store{ id:’ebay_store’ }) -[:located] -> () <- [:contains*0..2] - (locality) <- [:operates]- carrier RETURN carrier the query Locality id = california Locality id = marin_county Locality id = 94901 :contains Store id = ebay_store :located :contains Locality id = 94903 Locality id = 94902 :contains :contains :operates Carrier id = carrier_2 Carrier id = carrier_1 :operates :operates
  • 62. SELECT * FROM carriers LEFT JOIN locations ON carrier.location_id = location.id LEFT JOIN stores ON stores.location_id = carrier.location_id WHERE stores.name = ‘ebay_store’
  • 63. SELECT * FROM carriers LEFT JOIN locations ON carrier.location_id = location.id OR carrier.location_id = location.parent_id LEFT JOIN stores ON stores.location_id = carrier.location_id WHERE stores.name = ‘ebay_store’
  • 64. ?
  • 65. MATCH (store{ id:’ebay_store’ }) -[:located] -> () <- [:contains*0..2] - (locality) <- [:operates]- carrier RETURN carrier
  • 66. root (0) Year: 2013 Month: 05 Month: 01 :year_2015 :month_01:month_05 :year_2014 Year: 2015 Month: 06 :month_06 Day: 24 Day: 25 :day_24 :day_25 Day: 26 :day_26 Event 1 Event 2 Event 3 :happens :happens :happens :happens representing dates/times
  • 67. find all events on a specific day START root=node(0) MATCH root - [:year_2014] -> () -[:month_05] -> ()- [:day_24] -> () - [:happens] -> event RETURN event root (0) Year: 2013 Month: 05 Month: 01 :year_2015 :month_01:month_05 :year_2014 Year: 2015 Month: 06 :month_06 Day: 24 Day: 25 :day_24 :day_25 Day: 26 :day_26 Event 1 Event 2 Event 3 :happens :happens :happens :happens
  • 68. all together Locality id = california Locality id = marin_county Locality id = 94901 :contains Store id = ebay_store :located :contains Carrier id = carrier_1 :operates root (0) Year: 2013 Month: 05 :month_05 :year_2014 Day: 24 :day_24 hour 09 hour 10 :hour_09 :hour_10 hour 11 :hour_11 :available {premium: 1} :available {premium: 1.5}
  • 69. MATCH (store{ id:’ebay_store’ }) -[:located] -> (locality) <- [:operates]- carrier - [available:available] -> () <- [:hour_10] - () <- [:day_24] - () <- [:month_05] - () <- [:year_2014] - () RETURN carrier, available.premium as premium all together Locality id = california Locality id = marin_county Locality id = 94901 :contains Store id = ebay_store :located :contains Carrier id = carrier_1 :operates root (0) Year: 2013 Month: 05 :month_05 :year_2014 Day: 24 :day_24 hour 09 hour 10 :hour_09 :hour_10 hour 11 :hour_11 :available {premium: 1} :available {premium: 1.5}
  • 70. Other graph uses • Recommendation engines • Organisational analysis • Graphing your infrastructure
  • 71. • There was a learning curve in switching from a relational mentality to a graph one • Tooling not as mature as in the relational world • No out of the box solution for db migrations • Seeding an embedded database was unfamiliar Some gotchas
  • 72. • Setting up scenarios for tests was tedious • Built our own tool based on the geoff syntax developed by Nigel Small • Geoff allows modelling of graphs in textual form and provides an interface to insert them into an existing graph (A) {“name”: “Alice”} (B) {“name”: “Bob”} (A) -[:KNOWS] -> (B) •We created a Ruby dsl for modelling a graph and inserting it into the db that works with factory_girl • Open source - https://github.com/shutl/geoff Testing was a challenge
  • 73. Wrap Up • Neo4j and graph theory enabled Shutl to achieve big performance increases in its most important operation - calculating delivery prices • It’s a new tool based on tested theory, and cypher is the first language that allows you to query graphs in a declarative way (like SQL) • Tooling and adoption is immature but getting better all the time
  • 74. Thank you! ! Any questions? Sam Phillips Head of Engineering ! @samsworldofno http://samsworldofno.com sam@shutl.com Volker Pacher Senior Developer ! @vpacher https://github.com/vpacher volker@shutl.com