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

  • SEARCH
  • Home
  • 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 6875129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:16:56+00:00 2026-05-27T04:16:56+00:00

I’m working on a very simple email-like messaging functionality as part of an App

  • 0

I’m working on a very simple email-like messaging functionality as part of an App Engine application. It is simpler than email in that there are no “subject lines”. In other words, two users (or more, but not hundreds) can just exchange messages in a conversation thread that contains all of their back-and-forth messages (like IM, but with a thread that persists between sessions). So far, I’m thinking of modeling this with two types of entities: Message and Conversation

class Message(db.Model):
    sender = StringProperty(required=True)
    receiver = StringProperty(required=True)
    message = TextProperty(required=True)
    timestamp = DateTimeProperty(auto_now_add=True)

class Conversation(db.Model):
    messages = ListProperty(int) # List holding the datastore-assigned integer ids of the messages in this conversation
    users = StringListProperty()

Since creating a Message requires the creation or modification of a Conversation, I would like to store Message and Conversation in the same entity group so that those changes can occur in a transaction. I figured that I would have the Message entities as children of their associated Conversation entities.

The Message needs the key for the Conversation entity to specify it as a parent. The Conversation needs the id of the Message to store it in the messages property.

What is the most efficient way to do this?

  • If I have the datastore assign an id for the Conversation entity, then I need to (1) put the Conversation entity into the datastore to get its id, (2) put the Message entity into the datastore to get its id, and (3) update the Conversation entity to add the new message id and put it again into the datastore. This requires 3 trips to the datastore, which looks inefficient.
  • I could also create a unique key name for the Conversation entity (e.g., ‘;’.join(sorted(conv.users)). By doing this, I could avoid one of the three trips to the datastore outlined above.

Is there a way to do this with a single trip to the datastore? Am I worrying about a marginal amount of efficiency, which I should really not worry about? Is there a smarter design pattern for what I’m looking to do? If so, I would really appreciate a pointer.

  • 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-27T04:16:57+00:00Added an answer on May 27, 2026 at 4:16 am

    You’re inverting the conventional design pattern, which would be this:

    class Conversation(db.Model):
        users = StringListProperty()
    
    class Message(db.Model):
        sender = StringProperty(required=True)
        receiver = StringProperty(required=True)
        message = TextProperty(required=True)
        timestamp = DateTimeProperty(auto_now_add=True)
        conversation = db.ReferenceProperty(Conversation)
    

    In the model above, you don’t need to modify the conversation entity when you store a new message, unless you’re updating the user list. I would recommend using this unless there’s a reason not to.

    This should also be a bit more scalable. If your conversation reaches 1000 messages, you don’t have to store 1000 message ID properties on a single conversation entity.

    Let’s assume, though, that you want to keep your original model. To store the conversation and message in a single trip, you’d need to eager-assign the message ID. My advice here would be to generate a UUID (e.g. with uuid.uuid4()) and assign this as the message key name (and append it to the messages list), rather than waiting for the datastore to assign an ID.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.