Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficiently design and manage user settings module [closed]

I don't know, if this type of question is already asked or not. Actually I don't know what to search for. Am asking at the right place?

Just as an example, I always wonder how the social media giants like Facebook manages their user settings module... What would be the database design and how they manage to hide the user updates on his friends' timeline if he has chosen not to show his updates on that particular friends timeline. I mean if I had been programming there then I would have loaded all the settings value in an array and there would be many conditional statements to check each and every user setting and accordingly printed data.

But I think this would make that code unmanageable because there would be so many conditions which could lead to undesired results.

So my question is, is there any better approach to do this?

I don't know I am making any sense here, but I tried to explain my question.

like image 287
Sagar Guhe Avatar asked Feb 15 '15 06:02

Sagar Guhe


4 Answers

Facebook's data is maintained in document repository (Nosql) and efficient indexing is used to quickly find the tags and searches. This approach of search and data storage is markedly different from relational database based data storage and search.

Google also uses similar scheme to map the entire web and promptly give you back the result.

So in simpler terms you data is stored and indexed the way Google indexes messages, only difference is, the data is also lying with Facebook.

The related technologies are Bigdata, Mongodb, Apache Hadoop. And one of the leading index management and search algorithm is Lucene. Apache Elasticsearch is an user friendly package around Lucene.

So facebook treats these security critaria like tag (in simple language) and does google like search and presents you in a pleasing frontend, not sounding like a search engine.

While setting up your system, you can use elasticsearch to have faster search. Elasticsearch is makes implementation of lucene easier. It definitely will have some learning curve. Elasticsearch can also be used along with rdbms, in this case your data is saved in database but indexes also maintained to faster search. Definitely the cost would be disk-space. It makes it possible to have many criteria but still being able to get result quicker.

A quick tutorial on elasticsearch.

like image 131
Ashutosh Nigam Avatar answered Nov 19 '22 07:11

Ashutosh Nigam


There would be many conditions to evaluate, that is correct. But in a SELECT statement you can easily compose all of those conditions in a WHERE clause which is very efficient.

Essentially, as long as you're comparing on equality, the database can easily optimize that, allowing it to quickly search for posts that fit the desired constraints. Even though there are a lot conditions, they don't really affect performance when compared to the fact that there are millions of entries in a table to be searched.

like image 36
randomusername Avatar answered Nov 19 '22 07:11

randomusername


What your asking for is a result of really tough planing.. whenever you need to develop something that has a good potential to be complex you'll have to plan (Engineering) it well using known methodologies.

Usually the DB has many polymorphic relationships with entities, there are guys who are responsible of writing Query Procedures that should retrieve the wanted data fairly for the developers.

It's really not something you could come up with easy solution, the key here is planning, and planning good. there's no one right answer.

If your application is fairly small, you could just implement it your way, then you'll see what can be upgraded.. It's pretty much your only way to go. (BTW that's what most of statups are doing)

I wish you the best of luck.

like image 2
fadeys.work Avatar answered Nov 19 '22 06:11

fadeys.work


Regarding facebook's db schema's and how it works and why its a good design, here are some articles that would explain to you why:

The power of the graph

This is posted by facebook and it explains how they are managing data. They use TAO data model and through the application of graph theory and other complicated algorithms and advanced memoray caching and data handling, they can efficiently manage lots of user data..

but regarding to your question:
What would be the database design and how they manage to hide the user updates on his friends' timeline if he has chosen not to show his updates on that particular friends timeline?

  1. I think this post would give you some insights on what kind of db structure facebook has and what would be the functionality of it for every user: Social Network Friends Relationship Database Design

  2. Usually, the hiding of user updates on your friends' timeline if you have not shown your update to that particular friend is managed by storing values in the database.. you can create a view_type table in db and that would determine what kind of view the user can see, then issue a where condition in your sqls based on the view the user has selected.. there are still many ways to handle this and a good database structure is needed for this and of course planning for a good and efficient database is a very important and strict procedure..

like image 2
catzilla Avatar answered Nov 19 '22 05:11

catzilla