SlideShare a Scribd company logo
In a League of their Own:
Neo4j and Premiership Football
Mark Needham
@markhneedham
•
•
•
•
•
•

Intro to graphs
When do we need a graph?
Property graph model
Neo4j’s query language
The football graph
Using Neo4j from .NET

Outline
Let’s talk graphs
Dancing With
Michael Jackson

Eating Brains

You mean these?
Dancing With
Michael Jackson

Eating Brains

Nope!
Node

Relationship

Ok so what’s a graph then?
The tube
The social network (graph)
Complexity
What are graphs good for?
complexity = f(size, semi-structure, connectedness)

Data Complexity
Size
complexity = f(size

, semi-structure, connectedness)

The Real Complexity
Semi-Structure
USER_ID

FIRST_NAME

LAST_NAME

EMAIL_1

EMAIL_2

FACEBOOK

315

Mark

Needham

mark.needham@neotech
nology.com

m.h.needham@gmail.com

NULL

Email: mark.needham@neotechnology.com
Email: m.h.needham@gmail.com
Twitter: @markhneedham
Skype: mk_jnr1984

TWITTER
@markhneedham

CONTACT

USER

Semi-Structure

CONTACT_TYPE

SKYPE
mk_jnr1984
complexity = f(size

, semi-structure, connectedness)

The Real Complexity
Connectedness
Connectedness
Connectedness
Densely Connected

Semi Structured

When do we need a graph?
Lots of join tables
Densely connected?
Lots of sparse
tables
Semi-Structured?
• Millions of ‘joins’ per second
• Consistent query times as dataset
grows
• Join Complexity and Performance
• Easy to evolve data model
• Easy to ‘layer’ different types of
data together

Properties of graph databases
Property Graph Data Model
Nodes
• Used to represent entity attributes and/or metadata
(e.g. timestamps, version)
• Key-value pairs
• Java primitives
• Arrays
• null is not a valid value
• Every node can have different properties

Nodes can have properties
What’s a node?
Relationships
• Relationships are first class citizens
• Every relationship has a name and a direction
– Add structure to the graph
– Provide semantic context for nodes

• Properties used to represent quality or weight
of relationship, or metadata
• Every relationship must have a start node and
end node

Relationships
Nodes can be connected by
more than one relationship

Nodes can have more
than one relationship
Self relationships are allowed

Relationships
Labels
Think Gmail labels
• Nodes
– Entities

• Relationships
– Connect entities and structure domain

• Properties
– Entity attributes, relationship qualities, and
metadata

• Labels
– Group nodes by role

Four Building Blocks
Purposeful abstraction of a domain designed to
satisfy particular application/end-user goals

Models
Model
Query

Design for Queryability
Model

Design for Queryability
Model
Query

Design for Queryability
• Declarative Pattern-Matching language
• SQL-like syntax
• Designed for graphs

Introducing Cypher
A

B

C

Patterns, patterns, everywhere
a

b

(a) --> (b)
It’s all about the ASCII art!
MATCH (a)-->(b)
RETURN a, b

a

b

The most basic query
a

ACTED IN

m

(a)–[:ACTED_IN]->(m)
Adding in a relationship type
MATCH (a)-[:ACTED_IN]->(m)
RETURN a.name, m.name

a

ACTED IN

m

Adding in a relationship type
The football graph
The football graph
Find Arsenal’s away matches
Find Arsenal’s away matches
MATCH (team:Team)<-[:away_team]-(game)
WHERE team.name = "Arsenal"
RETURN game

Find Arsenal’s away matches
MATCH (team:Team)<-[:away_team]-(game)
WHERE team.name = "Arsenal"
RETURN game.name

Graph Pattern
MATCH (team:Team)<-[:away_team]-(game)
WHERE team.name = "Arsenal"
RETURN game.name

Anchor pattern in graph
MATCH (team:Team)<-[:away_team]-(game)
WHERE team.name = "Arsenal"
RETURN game.name

Create projection of results
Find Arsenal’s away matches
Evolving the football graph
Find the top away goal scorers
MATCH (team)<-[:away_team]-(game:Game),

(game)<-[:contains_match]-(season:Season),
(team)<-[:for]-(stats)<-[:played]-(player),
(stats)-[:in]->(game)
WHERE season.name = "2012-2013"
RETURN player.name,
COLLECT(DISTINCT team.name),
SUM(stats.goals) as goals
ORDER BY goals DESC
LIMIT 10

Find the top away goal scorers
MATCH (team)<-[:away_team]-(game:Game),

(game)<-[:contains_match]-(season:Season),
(team)<-[:for]-(stats)<-[:played]-(player),
(stats)-[:in]->(game)
WHERE season.name = "2012-2013"
RETURN player.name,
COLLECT(DISTINCT team.name),
SUM(stats.goals) as goals
ORDER BY goals DESC
LIMIT 10

Multiple graph patterns
MATCH (team)<-[:away_team]-(game:Game),

(game)<-[:contains_match]-(season:Season),
(team)<-[:for]-(stats)<-[:played]-(player),
(stats)-[:in]->(game)
WHERE season.name = "2012-2013"
RETURN player.name,
COLLECT(DISTINCT team.name),
SUM(stats.goals) as goals
ORDER BY goals DESC
LIMIT 10

Anchor pattern in the graph
MATCH (team)<-[:away_team]-(game:Game),

(game)<-[:contains_match]-(season:Season),
(team)<-[:for]-(stats)<-[:played]-(player),
(stats)-[:in]->(game)
WHERE season.name = "2012-2013"
RETURN player.name,
COLLECT(DISTINCT team.name),
SUM(stats.goals) as goals
ORDER BY goals DESC
LIMIT 10

Group by player
Find the top away goal scorers
• Goals scored in each month by
Michu
• Tottenham results when Gareth Bale
scores
• What did Wayne Rooney do in April?
• Which players only score when a
game is televised?

Other football queries
Graph Query Design
The relational version
Relational

Graphs

Tables

Nodes
- no need to set a property if it

- assume records all have the
same structure

doesn’t exist

Foreign keys between tables Relationships
- joins calculated at run time
- stored as a ‘Pre-computed
- the more tables you join to a
query the slower the query gets

index’ at write time
- very easy to do lots of ‘hops’
between relationships

Graph vs Relational
Neo4j Server

Application
H
T
T
P
REST Client

.NET and Neo4j
Neo4j Server

Application
H
T
T
P

Neo4jClient
REST Client

.NET and Neo4j
.NET and Neo4j
.NET and Neo4j
.NET and Neo4j
.NET and Neo4j
.NET and Neo4j
Thinking in graphs
Graphs should be fun!
Last Wednesday of the month

Ask for help if you get stuck
www.graphdatabases.com

Come take a copy, it’s free!
Mark Needham
@markhneedham
mark.needham@neotechnology.com

Questions?

More Related Content

PPTX
8 system models (1)
PPSX
System Development Methodologies
PPT
Chapter 15 software product metrics
PPTX
Software Trends
PPT
Software Engineering (Requirements Engineering & Software Maintenance)
PDF
Traditional Process Models
PPT
Chapter 2 part 1
PPTX
Relating to IT & marketing Lockitron
8 system models (1)
System Development Methodologies
Chapter 15 software product metrics
Software Trends
Software Engineering (Requirements Engineering & Software Maintenance)
Traditional Process Models
Chapter 2 part 1
Relating to IT & marketing Lockitron

Viewers also liked (12)

PDF
Global BRT (Bus Rapid Transit ) Market
PPT
Philippines provincial bus industry
PDF
Global Hybrid and Electric Transit Bus Market
PDF
The #StartupStack
RTF
DOCX
Tata International business mgt
PPT
Globalization of TATA Motors
PDF
Tata motors - International Business Project Report
DOCX
INTERNATIONAL MARKETING OF TATA MOTORS
DOC
A project report on Competitor analysis of_tata_motors
PDF
How Steve Jobs Would Disrupt The Truck & Bus Industry
PPTX
Tyre Industry Analysis
Global BRT (Bus Rapid Transit ) Market
Philippines provincial bus industry
Global Hybrid and Electric Transit Bus Market
The #StartupStack
Tata International business mgt
Globalization of TATA Motors
Tata motors - International Business Project Report
INTERNATIONAL MARKETING OF TATA MOTORS
A project report on Competitor analysis of_tata_motors
How Steve Jobs Would Disrupt The Truck & Bus Industry
Tyre Industry Analysis
Ad

Similar to Football graph - Neo4j and the Premier League (20)

PDF
The Football Graph - Neo4j and the Premier League
PDF
The 2nd graph database in sv meetup
PPTX
Introduction to SQL Server Graph DB
PDF
Graph Search: The Power of Connected Data
PDF
Tactical data engineering
PPTX
Graph db - Pramati Technologies [Meetup]
PDF
managing big data
PDF
Neo4j Graph Database และการประยุกตร์ใช้
PPS
Introduction to Bootstrap: Design for Developers
PDF
Designing and Building a Graph Database Application - Ian Robinson (Neo Techn...
PDF
Data Modeling with Neo4j
PPTX
Intro to Cypher
PPT
Cypher
PDF
Graph Features in Spark 3.0: Integrating Graph Querying and Algorithms in Spa...
PDF
Designing and Building a Graph Database Application – Architectural Choices, ...
PDF
Introduction to Graphs with Neo4j
PPTX
The openCypher Project - An Open Graph Query Language
PPTX
Optimizing Cypher Queries in Neo4j
PPTX
GDM 2011 Talk
PPTX
Graphs fun vjug2
The Football Graph - Neo4j and the Premier League
The 2nd graph database in sv meetup
Introduction to SQL Server Graph DB
Graph Search: The Power of Connected Data
Tactical data engineering
Graph db - Pramati Technologies [Meetup]
managing big data
Neo4j Graph Database และการประยุกตร์ใช้
Introduction to Bootstrap: Design for Developers
Designing and Building a Graph Database Application - Ian Robinson (Neo Techn...
Data Modeling with Neo4j
Intro to Cypher
Cypher
Graph Features in Spark 3.0: Integrating Graph Querying and Algorithms in Spa...
Designing and Building a Graph Database Application – Architectural Choices, ...
Introduction to Graphs with Neo4j
The openCypher Project - An Open Graph Query Language
Optimizing Cypher Queries in Neo4j
GDM 2011 Talk
Graphs fun vjug2
Ad

More from Mark Needham (13)

PDF
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
PDF
This week in Neo4j - 3rd February 2018
PDF
Building a recommendation engine with python and neo4j
PDF
Graph Connect: Tuning Cypher
PDF
Graph Connect: Importing data quickly and easily
PDF
Graph Connect Europe: From Zero To Import
PDF
Optimizing cypher queries in neo4j
PPTX
Scala: An experience report
PPTX
Visualisations
PPTX
Mixing functional programming approaches in an object oriented language
PPT
Mixing functional and object oriented approaches to programming in C#
PPT
Mixing functional and object oriented approaches to programming in C#
PDF
F#: What I've learnt so far
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
This week in Neo4j - 3rd February 2018
Building a recommendation engine with python and neo4j
Graph Connect: Tuning Cypher
Graph Connect: Importing data quickly and easily
Graph Connect Europe: From Zero To Import
Optimizing cypher queries in neo4j
Scala: An experience report
Visualisations
Mixing functional programming approaches in an object oriented language
Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#
F#: What I've learnt so far

Recently uploaded (20)

PPTX
BADMINTON-2ND-WEEK-FUNDAMENTAL-SKILLS.pptx
PDF
FIFA Club World Cup 2025 - USA Chelsea VS PSG in Finals
DOCX
Soccer World Cup Tickets Telemundo’s Big Plans for FIFA World Cup 2026.docx
PDF
Lionel Messi The Unparalleled Legacy of Football's Greatest Player.pdf
DOCX
From Playgrounds to Pitches Empowering the Next Generation.docx
PPTX
Basketball_Basics_Guide_for_kids_parents.pptx
PPTX
Daniel Oordt | Club Colors to National Pride: The World Cup's Role in Unity
PDF
2025 AASM Schedule of Oral Presentations
DOCX
NFL Dublin Will Howard’s Preseason Be Over After Hand Injury.docx
DOCX
FIFA World Cup Tickets Rodrigo De Paul’s Inter Miami Move and Its FIFA 2026 I...
PDF
Football World Cup Top 10 Teams Aiming for the FIFA 2026 Trophy.pdf
PDF
Board of Boxing Sport Regulations - Dealing with Standard Rules and Regulatio...
PDF
Navigating the Sports Betting Landscape From @OffshoreInside
DOCX
NFL Dublin Minnesota’s Offensive Edge, the Josh Oliver Effect.docx
DOCX
NFL Dublin Steelers Release Patterson Early in Training Camp.docx
DOCX
NFL Dublin Addison Fuels Steelers-Vikings Showdown.docx
DOCX
Furniture Movers in Dubai | Best Mover In Dubai
DOCX
FIFA World Cup 2026 Las Vegas to Host FIFA 2026 Draw Ceremony.docx
PPTX
Soccer_Basics_Presentation_about_and_info.pptx
DOCX
NFL Dublin Steelers Lesser Shows Depth and Power at Camp.docx
BADMINTON-2ND-WEEK-FUNDAMENTAL-SKILLS.pptx
FIFA Club World Cup 2025 - USA Chelsea VS PSG in Finals
Soccer World Cup Tickets Telemundo’s Big Plans for FIFA World Cup 2026.docx
Lionel Messi The Unparalleled Legacy of Football's Greatest Player.pdf
From Playgrounds to Pitches Empowering the Next Generation.docx
Basketball_Basics_Guide_for_kids_parents.pptx
Daniel Oordt | Club Colors to National Pride: The World Cup's Role in Unity
2025 AASM Schedule of Oral Presentations
NFL Dublin Will Howard’s Preseason Be Over After Hand Injury.docx
FIFA World Cup Tickets Rodrigo De Paul’s Inter Miami Move and Its FIFA 2026 I...
Football World Cup Top 10 Teams Aiming for the FIFA 2026 Trophy.pdf
Board of Boxing Sport Regulations - Dealing with Standard Rules and Regulatio...
Navigating the Sports Betting Landscape From @OffshoreInside
NFL Dublin Minnesota’s Offensive Edge, the Josh Oliver Effect.docx
NFL Dublin Steelers Release Patterson Early in Training Camp.docx
NFL Dublin Addison Fuels Steelers-Vikings Showdown.docx
Furniture Movers in Dubai | Best Mover In Dubai
FIFA World Cup 2026 Las Vegas to Host FIFA 2026 Draw Ceremony.docx
Soccer_Basics_Presentation_about_and_info.pptx
NFL Dublin Steelers Lesser Shows Depth and Power at Camp.docx

Football graph - Neo4j and the Premier League

Editor's Notes

  • #2: In this talk, we&apos;ll look at how graph data and Neo4j can be used to model the English Premier League. We&apos;ll see how the graph model and Cypher query language makes it natural and fun to query multidimensional semi-structured data. We&apos;ll also see how graphs encourage discoverability so that we can spot interesting correlations and become king of the arcane football facts (e.g. how many goals have been scored at grounds in the North West of England by players originating from South America) at your local pub quiz. We&apos;ll also see what the graph model would look like if modeled in a relational way and show where the approach reaches its limits and the graph addresses and resolves those challenges.
  • #4: Let’s get started and talk about graphs. Now in this context we’re thinking more of what are sometimes known as networks and…
  • #5: …many people when they hear the word graph think of this.
  • #6: Which isn’t what we’re going to be talking about today!
  • #7: It’s not a new thing, you’ll already be familiar with lots of things that are graphs but perhaps you don’t know it yet. The London tube is perhaps the most famous example that Londoners at least use every day
  • #8: It’s not a new thing, you’ll already be familiar with lots of things that are graphs but perhaps you don’t know it yet. The London tube is perhaps the most famous example that Londoners at least use every day
  • #9: Or if not then you’ve certainly heard of the social network (graph)
  • #17: An organisational hierarchy is a common model
  • #18: An organisational hierarchy is a common model
  • #19: Or of course as we mentioned earlier, a social network of friends of friends and so on is a popular graph
  • #22: Null values all over the place
  • #24: Now, as I say, graph databases allow you to store, manage and query your data as a graph. Neo4j adopts a very particular graph model, which we call the property graph model.So I’m going to spend the next few minutes talking about the important aspects of this model in more detail.In fact, I’m going to talk about the enhanced property graph model, which will be available in Neo4j 2.0 sometime later this year.
  • #29: Pointer in memory and ultimately on disk
  • #31: Analogy: Gmail labels. Every mail can have zero or more labels attached. Allow you to associate filters with groups of emails.
  • #34: Always motivated by needs, problems, goals: not transparent window onto realityC18: Seven Bridges of KönigsbergGoal: Find path through the city that crosses each bridge once and once only
  • #38: Which leads us perfectly into neo4j’s query language
  • #44: Football is quite a nice domain for
  • #45: Football is quite a nice domain for modelling in graphs because the data has a lot of dimensions to it
  • #46: Football is quite a nice domain for
  • #47: Football is quite a nice domain for
  • #48: Football is quite a nice domain for
  • #49: Football is quite a nice domain for
  • #50: Football is quite a nice domain for
  • #51: Football is quite a nice domain for
  • #52: Football is quite a nice domain for
  • #53: Football is quite a nice domain for
  • #54: Football is quite a nice domain for
  • #55: Football is quite a nice domain for
  • #56: Football is quite a nice domain for
  • #57: Football is quite a nice domain for
  • #58: Football is quite a nice domain for
  • #59: Football is quite a nice domain for
  • #60: Football is quite a nice domain for
  • #61: -&gt; SQL - define your tables and relationships and generally don’t change that.Might denormalise or add indexes to speed up queries-&gt; Graphs – define your initial nodes and relationships. May then add ‘layers’ to the graph to make implicit relationships explicit
  • #62: Football is quite a nice domain for
  • #63: How is this different to a relational database? We have tables (nodes) and foreign keys between tables (relationships)Those are calculated at run time – in a graph a relationship is a first Class citizen. Effectively a pre-computed indexYou can also traverse lots of ‘hops’ which becomes quite expensive when You do
  • #72: If it’s not fun and It seems cumbersome then perhaps it’s the wrong tool for that particular data problem or it’s modeled in the wrong way. Might be worth asking
  • #73: Might be worth asking for help if that isn’t happening or you’re stuck. We have a good community on Stack Overflow and a mailing list as well. You’ll get answers to any questions you have pretty quickly.
  • #74: Please take a copy of t
  • #75: Might be worth asking for help if that isn’t happening or you’re stuck. We have a good community on Stack Overflow and a mailing list as well. You’ll get answers to any questions you have pretty quickly.