构建社交网络类型应用程序的模式?
我需要设计/架构/开发一个基于网络的社交网络类型应用程序。
基本功能:
- 用户在系统上创建帐户
- 用户同意彼此成为“好友”
- 用户在系统内创建内容
- 用户指定哪些朋友可以查看/编辑他们创建的内容
这个核心功能之前肯定已经创建过很多次了吗?是否有关于如何实现此类事情的最佳实践模式?
我最感兴趣的是数据库的外观。
从 SQL 角度(任何数据库)来看,这会是什么样子?
从 NOSQL 角度(任何 NOSQL 数据库)来看,这会是什么样子?
我最感兴趣的是,数据库中“内容可见性”的问题是如何解决的?即数据库/应用程序如何确保只有经过批准的朋友才能看到用户创建的内容?
谢谢
I need to design / architect / develop a web based social network type application.
Basic functionality:
- users create accounts on the system
- users agree to "friend" each other
- users create content within system
- users specifies which friends may view/edit content that they created
Surely this core functionality has been created many times before? Are there any best practice patterns out there for how to implement this sort of thing?
I'm most interested in how the database for this would look.
What would this look like from a SQL perspective (any database)?
What would this look like from a NOSQL perspective (any NOSQL database)?
The thing I am most interested in, is how is the question of "content visibility" solved within the database? i.e. how does the database/application ensure that only approved friends may see the user created content?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
首先要解决的是数据库,SQL 数据库看起来就像规范化的 SQL 数据库。它还能是什么样子? nosql 数据库看起来像一堆名称值对文件。
在对现有的流行和不受欢迎的网站进行大量研究之后构建社交网站的三种方法,以确定它们的架构和它们所针对的市场,以及它们为这些市场提供的特定服务。
如何处理“内容可见性”。当然,最初网站构建者会决定谁可以看到内容。仅限业主、朋友、注册用户、普通大众?等等。但这一决定必须符合网站的目标和政策。处理此问题的最佳方法是通过基于角色的访问 RBAC 请参阅此处了解详细信息
你说你“需要设计/架构/开发”是因为压倒性的内心冲动还是因为有人付钱给你?
不管怎样,请记住社交网络空间非常非常拥挤。如果您只是建立另一个 YouTube 或 Facebook,那么您不太可能能够产生使此类网站在商业上取得成功所需的临界数量。
如果它是针对尚未满足的利基市场,例如“佩克汉姆和布罗克利异国鸟类爱好者俱乐部”,那么您知道您的市场是什么以及需要什么功能,因此您认为最简单和最便宜的上述任何选项都可以使用过,但这取决于您来分析和执行。
当然,您可能对一个主流社交网站有一个想法,并且没有被其他网站覆盖,即您已经发现了神话般的“市场缺口”。在这种情况下,尽管去尝试,但要做好失望的准备。或不。
First thing to get out the way is the database, an SQL one would just look like a normalised sql database. What else could it look like? A nosql database would look like a bunch of name value pair files.
Three approaches to building a social web site after and only after you do a shed load of research on existing popular and unpopular ones to ascertain their architecture and the markets that that they are aimed at, and the particular services that they offer to these markets.
How is "content visibility" handled. Initially of course the site builder makes a decision on who can see content. Owners only, friends, registered users, the general public? etc. But this decision must fir in with the aims and policies of the site. The best way then to handle this is through Role Based Access RBAC see here for details
When you say you "need to design / architect / develop" is this because of an overwhelming inner urge or because someone is paying you?
Either way remember the social web space is very very crowded. If you are just building another YouTube, or FaceBook then you are unlikely to be able to generate the critical mass of number required to make such a site commercially successful.
If it is for a niche market not already catered for, e.g. "The Peckham and Brockley Exotic Bird Fanciers Club" then you know what you market is and what features will be required so any of the above options you deem the easiest and cheapest can be used but that is up to you to analyse and execute.
You may of course have an idea for a social site that is mainstream and is not covered by the other, i.e. you have spotted the mythological "gap in the market". In this case go for it but prepare to be disappointed. Or not.
您的设计应该是可维护的。这就是我的项目中的内容。
1.) Application.Infrastruct
2.) Application.DataModel
3.) Application.DataAccess
4.) Application.DomainObjects
5.) Application.BusinessLayer
6.) Application.WebClient 或 Application.WindowsClient
Application.BusinessObjects 在整个应用程序中使用,并且只要需要,它们就会跨所有层 [Application.DataModel 和 Application.Infrastruct 除外]
我的所有查询都只定义了 Application.DataModel。
Application.DataAccess 返回或采用业务对象作为任何数据访问操作的一部分。业务对象是在反射属性的帮助下创建的。每个业务对象都标记有映射到数据库中的目标表的属性,并且业务对象内的属性标记有映射到相应数据库表中的目标列的属性。
我的验证框架允许我在指定的 ValidationAttribute 的帮助下验证每个字段。
我的框架大量使用属性来自动执行大多数繁琐的任务,例如映射和验证。我还可以将新功能作为框架中的新方面。
在我的应用程序中,示例业务对象将如下所示。
User.cs
BookCollection.cs
Your design should be maintenable. This is what I have in my project.
1.) Application.Infrastructure
2.) Application.DataModel
3.) Application.DataAccess
4.) Application.DomainObjects
5.) Application.BusinessLayer
6.) Application.WebClient or Application.WindowsClient
Application.BusinessObjects are used across the application and they travel across all layers whenever neeeded [except Application.DataModel and Application.Infrastructure]
All my queries are defined only Application.DataModel.
Application.DataAccess returns or takes Business objects as part of any data-access operation. Business objects are created with the help of reflection attributes. Each business object is marked with an attribute mapping to target table in database and properties within the business object are marked with attributes mapping to target coloumn in respective data-base table.
My validation framework lets me validate each field with the help of designated ValidationAttribute.
My framrwork heavily uses Attributes to automate most of the tedious tasks like mapping and validation. I can also new feature as new aspect in the framework.
A sample business object would look like this in my application.
User.cs
BookCollection.cs
像 http://www.neo4j.org 这样的图形数据库是一个值得考虑的选择。它非常适合社交网络(例如 http://blog.neo4j.org/2009/09/social-networks-in-database-using-graph.html)和基于 ACL 的安全性(例如 http://wiki.neo4j.org/content/ACL )。
a Graph Database like http://www.neo4j.org is a choice to look at. It lends itself very well to both the social network (e.g. http://blog.neo4j.org/2009/09/social-networks-in-database-using-graph.html) and the ACL-based security (e.g. http://wiki.neo4j.org/content/ACL ).
您应该首先研究现有的社交网络(Facebook、Myspace 等)。有大量关于它们如何实施的信息。
You should first study the existing social networks out there (Facebook, Myspace, etc). There is a fair amount of information available about how they are implemented.
社交网络成功的关键不在于其所基于的技术,而在于它们为用户解决的问题。如果用户喜欢它,即使你的技术很糟糕,你也注定会成功。
[编辑]它是如何实施的?检查任何基于 SQL 的用户角色系统。在这种情况下,每个用户也是一个角色,可以添加为“允许访问”任何对象。根据您拥有的对象数量以及控件的细粒度,这可能意味着您有一个包含三列的表:
OBJECT、USER、ACCESS_TYPE
,其中ACCESS_TYPE
可以是OWNER
、READ
(朋友)、WRITE
(亲密朋友)之一。该表将变得相当大,但对于当今的数据库来说,几亿行已不再罕见。
The key to success for social networks is not the technology on which it is based but the problems they solve for the users. If the users like it, you're doomed for success even if your technology is crap.
[EDIT] How is it implemented? Check any SQL-based user role system. In this case, every user is also a role which can be added as "allowed to access" to any object. Depending on how many objects you have and how fine grained the control should be, that can mean that you have a table with three columns:
OBJECT, USER, ACCESS_TYPE
whereACCESS_TYPE
can be one ofOWNER
,READ
(friend),WRITE
(close friend).This table will become pretty large but a few 100 million rows is not uncommon for todays databases anymore.
正如 Aaroon 指出的,你应该首先问自己想要解决什么问题。
您希望人们分享什么内容?它真的应该只对朋友可见吗?如果您使内容公开可见,那么它会更容易且可扩展,因为显示的内容不依赖于谁正在观看该页面,并且您可以轻松缓存它。公开的用户生成内容吸引新用户。
如果您想限制访问并为用户提供将朋友组附加到资源的机会,我会使用简单的基于组的访问控制。让每个资源都有一组可以编辑该资源的用户和一组可以查看该资源的用户。
这样,每个资源都有两个单值属性,并且每个用户属于有限数量的组。您可以将 view-group 和 edit-group 属性附加到存储在 NOSQL 数据库、Lucene/Sphinx 等搜索引擎或 SQL 数据库中的行中的文档。查询用户可用的内容时,传递用户所属的所有组(在 SQL 中,您将使用
IN
子句,在 Sphinx 中setFilter('view-group', array(2,3 ,4))
数据库将仅返回用户可用的内容,因为您仅将 2 个整数值(视图组和编辑组)附加到文档中,因此您可以将它们存储在内存中。搜索快速且可扩展。As Aaroon pointed out, you should first ask youself what problem you want to solve.
What content do you want people to share? Should it really be visible only to friends? It is much easier and scalable if you make content publicly visible, because what content is displayed is not dependent on who is watching the page and you can cache it easily. Publicly available user-generated content attracts new users.
If you want to restrict access and give to the user the opportunity to attach groups of friends to a resource I would go with a simple group-based access control. Let each resource have a group of users which can edit the resource and a group of users who can see it.
That way each resource has two single value attributes, and each user belons to a finite number of group. You can attach the view-group and edit-group attributes to a document stored in a NOSQL database, a search engine like Lucene/Sphinx or a row in a SQL database. When querying for content available for the user, pass all groups the user belongs to (in SQL you would use
IN
clause, in SphinxsetFilter('view-group', array(2,3,4))
. The database would return only content available for the user. Because you are attaching only 2 integer values (view-group and edit-group) to a document, you can store them in memory which makes the search fast and scalable.最后看起来 Elgg 或 Dolphin 可能会满足我们的要求。这些似乎是用于滚动您自己的社交网络的 PHP 框架。我查看了 Facebook 平台,但没有任何地方清楚地解释它是什么 - 它似乎是 facebook 代码,但也许它只是插件 API 或其他东西的代码。
In the end it looks like Elgg or Dolphin might meet our requirements. These appear to be PHP frameworks for rolling your own social network. I looked at the Facebook platform but nowhere did it clearly explain just what it is - it appears to be the facebook code but perhaps it is only the code for an addon API or something.