Implementing Facebook Social Graph using Spring and Neo4j

Amr Saleh
Javarevisited
Published in
6 min readNov 3, 2021

--

A graph is a data structure that allows a representation of set of nodes and the relationships that links these nodes together. For Facebook we can think of nodes as user, group, page, post and comment. An edge could be friend, like, comment and join.

Facebook refers to nodes as objects and for relationships as associations.

Let’s look at the below graph and see what it explains.

From this graph we can understand the following:

  • Amr is a friend with both Sarah and Adam.
  • Amr created a post.
  • Sarah liked the post.
  • Adam commented on the post.
  • Amr liked the comment created by Adam.

Also, note that with each relation a reverse relation is created. So, you can know for instance who is created, liked or comment on a post.

Although this story focuses on the back-end side of this project, implementing the social graph, we will create a small version of Facebook app using Flutter to show how to consume this graph.

--

--

Amr Saleh
Javarevisited

I’m a software engineer who is passionate about software architecture and design. Enjoy coding in Java, Scala, and JavaScript.