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 3852780
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:22:06+00:00 2026-05-19T17:22:06+00:00

In my appengine python app, I have sharded counters that count the number of

  • 0

In my appengine python app, I have sharded counters that count the number of favs for a photo, and number of views.

I have Photo and Counter models. To order photos by popularity (# of favs), I should have the # of favs stored in my Photo entities (Photo.all().order(‘num_favs’)).
Since I’m keeping track of the num of favs in a sharded counter, I’m wondering what’s the most efficient way to update my Photo entities with the latest # of favs from the Counter model?

Here’s an abstract of how my models look like:

class Photo(db.Model):
  photo = db.BlobProperty() 
  favs = db.IntegerProperty() #num of favs

class Counter(db.Model):
  #key_name = key to a model that's to be counted - Photo in this case
  name =  db.StringProperty() #counted entity key
  count = db.IntegerProperty() #count
  type = db.StringProperty() #type of model to count, "Photo" in this example

#Very unefficient way of updating my Photo entities with the latest count from Counter:

fav_counters = Counter.all().filter('type =', 'Photo')

for fav in fav_counters:
  photo_fav = db.get(fav.name) #get the photo for which the fav count is for
  photo_fav.favs = fav.count
  photo_fav.put()

I would appreciate it if I could answers on:
1) The most efficient way to order entities based on their counters
2) If the logic I’m following to order entities based on their counters is correct – what’s the most efficient way to update the Photo entities with their counters?

Thank you!

  • 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-05-19T17:22:06+00:00Added an answer on May 19, 2026 at 5:22 pm

    If you need to sort or filter based on a value, you probably shouldn’t use a sharded counter, but rather use one of the alternatives. In short, they are:

    1. Simply use a regular counter. If you don’t expect the rate of updates to exceed 1-5QPS for extended periods (brief spikes are okay), then this should work fine.
    2. Put a task in the task queue when a user favorites or un-favorites a photo. Ensure the task queue has a limited execution rate to limit contention.
    3. Use one of the lossy but contention-free counter patterns, such as this one.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a newbie to python and the app engine. I have this code that
I have a simple Hello World application in Python that i'm using with AppEngine,
I have around 4000 entities that I need to insert into a Java App
I have an app which works well live on AppEngine. However, when I try
I have a App Engine/Python/Django application which has grown and been modified over the
I am playing with Google App Engine and Python and I cannot list the
I'd like to create an application that would run on Google's appengine. However, this
I have a medium sized Django project, (running on AppEngine if it makes any
I have a Google App Engine app - http://mylovelyapp.appspot.com/ It has a page -
Since the Google App Engine Datastore is based on Bigtable and we know that's

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.