zmdc
zmdc

Reputation: 117

Google App Engine Datastore entities. Efficiency and structure

I am interested in knowing the best structure, for speed and cost efficiency, of Google App Engine Datastore entities.

As an example, an app about Clubs.

Structure A:

A single ndb.Model entity per club with: Name, ID, Address, Contacts, Tags, Reviews, Images etc

Structure B:

Multiple Entities per club with a KeyProperty referencing the club.

  1. ndb.Model Entity A. Name and ID
  2. ndb.Model Entity B. Address
  3. ndb.Model Entity C. Contacts
  4. etc

Considering that users might only want to look up addresses of Clubs close to their location, or perhaps only search for a contact number for one Club, or might scroll through pages of information about various Clubs; what is the better structure / best practice for speed and cost efficiency?

Thanks.

Upvotes: 0

Views: 170

Answers (2)

janscas
janscas

Reputation: 629

Structure B, but all the extra models added as Structured Properties.

That will make the whole club a single entity

Upvotes: 1

Andrei Volgin
Andrei Volgin

Reputation: 41099

It all boils down to (a) reading pattern, and (b) writing pattern.

READ: If your most widely use-case is to show all the information about the club, keeping all information in a single entity will be a cheaper and a more efficient approach (one read instead of three).

WRITE: If your model includes many properties that are almost never changed and some properties that change very frequently, it's better to separate them into different entities, so that each update of a single entity does not trigger updates to all indexes.

It appears that in your example there are no reasons to split the entity into multiple models.

Upvotes: 1

Related Questions