Nithin
Nithin

Reputation: 5840

Realtime datastore in google datastore

I want to store some information about shops and sellers including catalogs in google cloud datastore. One initial architecture i can think of is (shop_info is a kind)

/shop_owner_info
/shop_info
/shop_info/catalog/item(x)

But the problem here is as the catalog is in same group the write is limited to 1 per sec. But there might me more than one update to catalog per second.

So my question is how can the above be structured so that i can get realtime updates to catalog.

Upvotes: 1

Views: 376

Answers (1)

Renato Byrro
Renato Byrro

Reputation: 3784

Use Namespaces, not Ancestor paths

What you need is a Multitenant structure. In Datastore, you do that by using Namespaces, not ancestor paths. See Multitenancy in Datastore docs.

Instead of /shop_info/catalog/item(x), you would have:

Entities:

  • owner
  • owner/shop (I suggest shop as a child of owner)
  • catalog_item (top-level, not child of shop)

Namespaces:

  • [shop name or ID]

Example:

Let's say John subscribes to your app and creates a 'SuperElectro' store. You would have two entities:

  • owner: 'John'
  • shop: 'SuperElectro' (could be a child of owner: 'John')

And one namespace:

  • SuperElectro (or its unique ID)

When you add a new item to SuperElecto's catalog, don't provide any ancestor/parent. Instead, provide a namespace which is a combination of the owner and shop:

In Python:

from google.appengine.api import namespace_manager
from google.appengine.ext import ndb

class CatalogItem(ndb.Model):
    name = ndb.StringProperty()
    category = ndb.StringProperty()

namespace_manager.set_namespace('SuperElectro')
item = CatalogItem(name='iPhone', category='Smartphone')
item.put()

In real world, you'd want to use something unique for the namespace: instead of 'SuperElectro', I'd suggest using the shop ID.

Hope it helps. Read more at Implementing Multitenancy Using Namespaces.

Upvotes: 1

Related Questions