Reputation: 5840
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
Reputation: 3784
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:
Let's say John subscribes to your app and creates a 'SuperElectro' store. You would have two entities:
And one namespace:
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