How to design a social database like Instagram

1,104 views
Skip to first unread message

5785...@gmail.com

unread,
Aug 9, 2016, 6:57:34 AM8/9/16
to Neo4j
Hello there,
as a new Neo4j user, I'm here to ask you design advices for the following scenario.
I would like to develop a mobile app with a social section that broadly acts like Instagram, therefore a feed with my last friends activity, their profile page, suggestions based on common interests and so on.

(please take a look at the sketch attached).

And here my questions:

1) While (User)-[FOLLOWS]->(User) relationship seams clear to me, with (User)-[POSTS]->(Media) first doubts come. Is it correct to add a node for every media a user will publish? Suppose 100-1000 pictures per user, it's clear that Neo4j should manage a lot of connections from early stages and I don't know if it's affordable in terms of required resources.

2) (User)-[LIKES]->(Media)
Because I red there isn't an atomic counter that safety let me store a property in a Media node (example: {likes: 291}, I thought of this solution. But again, I see an exponential growth of relations: what are your considerations about this?

3) In my schema, I represented a user feed like a tree, attaching new media to the last one with the [NEXT] relationship. 
This way, when a user opens someone else profile, I can fetch for Media with descending order and arbitrary limit for paginated results. Am I correct or is there a best strategy?
Maybe I could consider a Media root node, storing the last user's activity: this way I think it should be easier, from a user profile, querying for new followed user's activities, ins't it?

Thanks in advance for any advice,
Alessandro


Michael Hunger

unread,
Aug 9, 2016, 7:21:28 AM8/9/16
to ne...@googlegroups.com
I think your model looks quite good so far. One node per Media is totally fine.

In general I presume you want to see in your stream the 20 latest media of users you follow.

MATCH (me:User {id:{userid}})-[:FOLLOW]->(u:User)-[:POSTS]->()-[:NEXT*0..20]->(m:Media)
RETURN u, collect(m) as medias

Make sure to generate a large graph of the user, media, tag and follows data to load-test your system and queries.

HTH Michael



--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

5785...@gmail.com

unread,
Aug 9, 2016, 8:53:58 AM8/9/16
to Neo4j
Hi Michael,
thank you for your feedback about this pattern!
Since this is my first Neo4j project, I thought all these nodes and relationships meant a bad design and your reassurance is really helpful to me.
I'll be glad to share my experience with the community if someone else will face similar situation.

PS: because I wasn't able to se my post published, I asked the same on SO, so sorry for the duplicate.
Kind regards
Alessandro

To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.

Michael Hunger

unread,
Aug 9, 2016, 4:33:18 PM8/9/16
to ne...@googlegroups.com
Yes sorry, I was on vacation so the publication lagged a bit.

Let us know how it goes with the testing and if you need any help with the use-case queries.

Michael

To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages