Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8224239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:59:46+00:00 2026-06-07T14:59:46+00:00

In my application, we need to develop a FRIENDS relationship table in datastore. And

  • 0

In my application, we need to develop a FRIENDS relationship table in datastore. And of course a quick solution I’ve thought of would be this:

user     = db.ReferenceProperty(User, required=True, collection_name='user')
friend   = db.ReferenceProperty(User, required=True, collection_name='friends')

But, what would happen when the friend list grows to a huge number, say few thousands or more ? Will this be too inefficient ?

Performance is always a priority to us. This is very much needed, as we would have few more to follow this similar relationship design.

Please give advice on the best approach to design for FRIENDS relationship table using datastore within App Engine Python environment.

EDIT
Other than FRIENDS relationship, FOLLOWER relationship will be created as well. And I believe it will be very often enough all these relationship to be queries most of the time, for the reason social media oriented of my application tend to be.

For example, If I follow some users, I will get update as news feed on what they will be doing etc. And the activities will be increased over time. As for how many users, I can’t answer yet as we haven’t go live. But I foresee to have millions of users as we go on.

Hopefully, this would help for more specific advice or is there alternative to this approach ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:59:48+00:00Added an answer on June 7, 2026 at 2:59 pm

    Your FRIENDS model (and presumably also your FOLLOWERS model) should scale well. The tricky part in your system is actually aggregating the content from all of a user’s friends and followees.

    Querying for a list of a user’s is O(N), where N is the number of friends, due to the table you’ve described in your post. However, each of those queries requires another O(N) operation to retrieve content that the friend has shared. This leads to O(N^2) each time a user wants to see recent content. This particular query is bad for two reasons:

    1. An O(N^2) operation isn’t what you want to see in your core algorithm when designing a system for millions of users.
    2. App Engine tends to limit these kinds of queries. Specifically, the IN keyword you’d need to use in order to grab the list of shared items won’t work for more than 30 friends.

    For this particular problem, I’d recommend creating another table that links each user to each piece of shared content. Something like this:

    class SharedItems(db.Model):
      user = db.ReferenceProperty(User, required=True) # logged-in user
      from = db.ReferenceProperty(User, required=True) # who shared it
      item = db.ReferenceProperty(Item, required=True) # the item itself
      posted = db.DateTimeProperty() # when it was shared
    

    When it comes time to render the stream of updates, you need an O(N) query (N is the number of items you want to display) to look up all the items shared with the user (ordered by date descending). Keep N small to keep this as fast as possible.

    Sharing an item requires creating O(N) SharedItems where N is the number of friends and followers the poster has. If this number is too large to handle in a single request, shard it out to a task queue or backend.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to develop a classic asp application on vista, and would like to
I need to develop a forms application with a DB backend. In future this
I need to develop a simple application that allows the user to write some
I need to develop an in-house real-time event analytics solution for our web application
I need to develop a application for a user's management in a IT Project.
I need to develop an application on Android platform that enables a client to
I need to develop some sort of application featuring Editing Movie slices, Adding and
i need to develop an iPhone application that is a Client of serverside application.
I need to develop an android application which do some image processing on the
I need to run/develop a mono-based application on a new dedicated server, and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.