构建社交网络类型应用程序的模式?

发布于 2024-08-16 00:26:30 字数 368 浏览 8 评论 0原文

我需要设计/架构/开发一个基于网络的社交网络类型应用程序。

基本功能:
- 用户在系统上创建帐户
- 用户同意彼此成为“好友”
- 用户在系统内创建内容
- 用户指定哪些朋友可以查看/编辑他们创建的内容

这个核心功能之前肯定已经创建过很多次了吗?是否有关于如何实现此类事情的最佳实践模式?

我最感兴趣的是数据库的外观。

从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

著墨染雨君画夕 2024-08-23 00:26:30

首先要解决的是数据库,SQL 数据库看起来就像规范化的 SQL 数据库。它还能是什么样子? nosql 数据库看起来像一堆名称值对文件。

在对现有的流行和不受欢迎的网站进行大量研究之后构建社交网站的三种方法,以确定它们的架构和它们所针对的市场,以及它们为这些市场提供的特定服务。

  1. 从头开始(和/或使用框架)。像 Facebook、Beebo、Myspace 等。这显然是到达那里的最长路线,但这确实意味着当您到达时您有东西可以卖。平台、会员资格和 USP 都是您的,可以出售给鲁珀特·默多克或任何人。
  2. 使用适用于社交网站的 CMS,并使用基本功能、插件以及您自己的灵感来打入目标市场。在这个领域,Drupal 经常被使用(我也成功地使用过),但 Joomla、Xaraya 和许多其他免费和付费的都可以使用。是的,更多研究。当 Rupert 给你敲响警钟时,这里卖的东西就更少了,因为基本工具可能是 GPL 的。
  3. 使用所提供的系统之一,你可以在其中注册,然后使用这些工具来构建你自己的系统,但所有的好东西都提供了,这些被称为白色标签网站。 从这里开始查看。如果有人想接管你,你就没有什么可卖的。

如何处理“内容可见性”。当然,最初网站构建者会决定谁可以看到内容。仅限业主、朋友、注册用户、普通大众?等等。但这一决定必须符合网站的目标和政策。处理此问题的最佳方法是通过基于角色的访问 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.

  1. Roll your own from scratch (and or use a framework). Like Facebook, Beebo, Myspace et al. This is obviously the longest route to getting there but it does mean you have something to sell when you do. Both the platform and the membership and the USP are yours to sell to Rupert Murdoch or whomever.
  2. Use a CMS that lends itself to social site and use the basic functionality, plus the plug-ins plus your own inspiration to hit your target market. In this area Drupal is often used (i have used it successfully as well) but Joomla, Xaraya and many other both free and paid for can be used. Yep more research. Less to sell here when Rupert gives you a bell as the base tool is probably GPL'd
  3. Use one of the provided system where you sign up and then use the tools to build your own but all the goodies are provided, These are known as white label sites. Start looking here. Here you have little to sell on if someone wants to take you over.

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.

秋千易 2024-08-23 00:26:30

您的设计应该是可维护的。这就是我的项目中的内容。

1.) Application.Infrastruct

  • 所有业务对象的基类、业务对象集合、数据访问类以及我的自定义属性和实用程序作为扩展方法、通用验证框架。这决定了我的最终 .net 应用程序的整体行为组织。

2.) Application.DataModel

  • 数据库的类型化数据集。
  • TableAdapters 扩展为包含事务和我可能需要的其他功能。

3.) Application.DataAccess

  • 数据访问类。
  • 使用底层类型数据集查询数据库操作的实际位置。

4.) Application.DomainObjects

  • 业务对象和业务对象集合。
  • 枚举。

5.) Application.BusinessLayer

  • 提供可从表示层访问的管理器类。
  • HttpHandlers。
  • 我自己的 Page 基类。
  • 更多内容请参见此处。

6.) Application.WebClientApplication.WindowsClient

  • 我的表示层
  • 从 Application.BusinessLayer 和 Application.BusinessObjects 获取引用。

Application.BusinessObjects 在整个应用程序中使用,并且只要需要,它们就会跨所有层 [Application.DataModel 和 Application.Infrastruct 除外]

我的所有查询都只定义了 Application.DataModel。

Application.DataAccess 返回或采用业务对象作为任何数据访问操作的一部分。业务对象是在反射属性的帮助下创建的。每个业务对象都标记有映射到数据库中的目标表的属性,并且业务对象内的属性标记有映射到相应数据库表中的目标列的属性。

我的验证框架允许我在指定的 ValidationAttribute 的帮助下验证每个字段。

我的框架大量使用属性来自动执行大多数繁琐的任务,例如映射和验证。我还可以将新功能作为框架中的新方面。

在我的应用程序中,示例业务对象将如下所示。

User.cs

[TableMapping("Users")]
public class User : EntityBase
{
    #region Constructor(s)
    public AppUser()
    {
        BookCollection = new BookCollection();
    }
    #endregion

    #region Properties

    #region Default Properties - Direct Field Mapping using DataFieldMappingAttribute

    private System.Int32 _UserId;

    private System.String _FirstName;
    private System.String _LastName;
    private System.String _UserName;
    private System.Boolean _IsActive;

    [DataFieldMapping("UserID")]
    [DataObjectFieldAttribute(true, true, false)]
    [NotNullOrEmpty(Message = "UserID From Users Table Is Required.")]
    public override int Id
    {
        get
        {
            return _UserId;
        }
        set
        {
            _UserId = value;
        }
    }

    [DataFieldMapping("UserName")]
    [Searchable]
    [NotNullOrEmpty(Message = "Username Is Required.")]
    public string UserName
    {
        get
        {
            return _UserName;
        }
        set
        {
            _UserName = value;
        }
    }

    [DataFieldMapping("FirstName")]
    [Searchable]
    public string FirstName
    {
        get
        {
            return _FirstName;
        }
        set
        {
            _FirstName = value;
        }
    }

    [DataFieldMapping("LastName")]
    [Searchable]
    public string LastName
    {
        get
        {
            return _LastName;
        }
        set
        {
            _LastName = value;
        }
    }

    [DataFieldMapping("IsActive")]
    public bool IsActive
    {
        get
        {
            return _IsActive;
        }
        set
        {
            _IsActive = value;
        }
    }

    #region One-To-Many Mappings
    public BookCollection Books { get; set; }

    #endregion

    #region Derived Properties
    public string FullName { get { return this.FirstName + " " + this.LastName; } }

    #endregion

    #endregion

    public override bool Validate()
    {
        bool baseValid = base.Validate();
        bool localValid = Books.Validate();
        return baseValid && localValid;
    }
}

BookCollection.cs

/// <summary>
/// The BookCollection class is designed to work with lists of instances of Book.
/// </summary>
public class BookCollection : EntityCollectionBase<Book>
{
    /// <summary>
    /// Initializes a new instance of the BookCollection class.
    /// </summary>
    public BookCollection()
    {
    }

    /// <summary>
    /// Initializes a new instance of the BookCollection class.
    /// </summary>
    public BookCollection (IList<Book> initialList)
        : base(initialList)
    {
    }
}

Your design should be maintenable. This is what I have in my project.

1.) Application.Infrastructure

  • Base classes for all businessobjects, busines object collection, data-access classes and my custom attributes and utilities as extension methods, Generic validation framework. This determines overall behavior organization of my final .net application.

2.) Application.DataModel

  • Typed Dataset for the Database.
  • TableAdapters extended to incorporate Transactions and other features I may need.

3.) Application.DataAccess

  • Data access classes.
  • Actual place where Database actions are queried using underlying Typed Dataset.

4.) Application.DomainObjects

  • Business objects and Business object collections.
  • Enums.

5.) Application.BusinessLayer

  • Provides manager classes accessible from Presentation layer.
  • HttpHandlers.
  • My own Page base class.
  • More things go here..

6.) Application.WebClient or Application.WindowsClient

  • My presentation layer
  • Takes references from Application.BusinessLayer and Application.BusinessObjects.

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

[TableMapping("Users")]
public class User : EntityBase
{
    #region Constructor(s)
    public AppUser()
    {
        BookCollection = new BookCollection();
    }
    #endregion

    #region Properties

    #region Default Properties - Direct Field Mapping using DataFieldMappingAttribute

    private System.Int32 _UserId;

    private System.String _FirstName;
    private System.String _LastName;
    private System.String _UserName;
    private System.Boolean _IsActive;

    [DataFieldMapping("UserID")]
    [DataObjectFieldAttribute(true, true, false)]
    [NotNullOrEmpty(Message = "UserID From Users Table Is Required.")]
    public override int Id
    {
        get
        {
            return _UserId;
        }
        set
        {
            _UserId = value;
        }
    }

    [DataFieldMapping("UserName")]
    [Searchable]
    [NotNullOrEmpty(Message = "Username Is Required.")]
    public string UserName
    {
        get
        {
            return _UserName;
        }
        set
        {
            _UserName = value;
        }
    }

    [DataFieldMapping("FirstName")]
    [Searchable]
    public string FirstName
    {
        get
        {
            return _FirstName;
        }
        set
        {
            _FirstName = value;
        }
    }

    [DataFieldMapping("LastName")]
    [Searchable]
    public string LastName
    {
        get
        {
            return _LastName;
        }
        set
        {
            _LastName = value;
        }
    }

    [DataFieldMapping("IsActive")]
    public bool IsActive
    {
        get
        {
            return _IsActive;
        }
        set
        {
            _IsActive = value;
        }
    }

    #region One-To-Many Mappings
    public BookCollection Books { get; set; }

    #endregion

    #region Derived Properties
    public string FullName { get { return this.FirstName + " " + this.LastName; } }

    #endregion

    #endregion

    public override bool Validate()
    {
        bool baseValid = base.Validate();
        bool localValid = Books.Validate();
        return baseValid && localValid;
    }
}

BookCollection.cs

/// <summary>
/// The BookCollection class is designed to work with lists of instances of Book.
/// </summary>
public class BookCollection : EntityCollectionBase<Book>
{
    /// <summary>
    /// Initializes a new instance of the BookCollection class.
    /// </summary>
    public BookCollection()
    {
    }

    /// <summary>
    /// Initializes a new instance of the BookCollection class.
    /// </summary>
    public BookCollection (IList<Book> initialList)
        : base(initialList)
    {
    }
}
滥情空心 2024-08-23 00:26:30

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 ).

陈年往事 2024-08-23 00:26:30

您应该首先研究现有的社交网络(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.

夜空下最亮的亮点 2024-08-23 00:26:30

社交网络成功的关键不在于其所基于的技术,而在于它们为用户解决的问题。如果用户喜欢它,即使你的技术很糟糕,你也注定会成功。

[编辑]它是如何实施的?检查任何基于 SQL 的用户角色系统。在这种情况下,每个用户也是一个角色,可以添加为“允许访问”任何对象。根据您拥有的对象数量以及控件的细粒度,这可能意味着您有一个包含三列的表:OBJECT、USER、ACCESS_TYPE,其中 ACCESS_TYPE 可以是OWNERREAD(朋友)、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 where ACCESS_TYPE can be one of OWNER, READ (friend), WRITE (close friend).

This table will become pretty large but a few 100 million rows is not uncommon for todays databases anymore.

病毒体 2024-08-23 00:26:30

正如 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 Sphinx setFilter('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.

时光清浅 2024-08-23 00:26:30

最后看起来 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文