Skip to content

Commit 9526cd9

Browse files
author
Sam Kleinman
committed
DOCS-201 merging in review comments from antoine
2 parents b171f5b + b9645e6 commit 9526cd9

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

draft/use-cases/gaming-user-state.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ There are a few things to note about this document:
140140
character record means you don't have to perform a separate query
141141
to fetch item details necessary for display.
142142

143+
.. should note that using unbounded lists on items can be an issue, past 1000 entries should prob normalize.
144+
Also if it ends up being much larger than core data itself, may want to split into own document, to better use RAM.
145+
146+
.. Dont understand why the whole location info is stored here: lots of duplication and consistency issues.
147+
Should normalize here and just store location name / coordinates
148+
143149
Items
144150
`````
145151

@@ -189,6 +195,9 @@ attribute of the ``character`` documents. The application will use
189195
``location`` as the system of record for interactions between multiple
190196
characters or between characters and non-inventory items.
191197

198+
.. should avoid storing player information in list here, it may grow and get updated too often if it's MMO.
199+
Instead rely on index on location on the user collection
200+
192201
Operations
193202
----------
194203

@@ -233,7 +242,7 @@ window, you need to merge the information from the ``armor`` and
233242
``weapons`` attributes with information from the ``inventory``
234243
attribute.
235244

236-
Suppose, for instance, that your code is displays armor data using the
245+
Suppose, for instance, that your code displays armor data using the
237246
following Jinja2 template:
238247

239248
.. code-block:: html
@@ -391,6 +400,8 @@ and adds it to their inventory:
391400
{ '_id': character['location']['id'] },
392401
{ '$pull': { 'inventory': { 'id': item_id } } })
393402

403+
.. should not require the $pull from location.inventory
404+
394405
While the above code may be for a single-player game, if you allow
395406
multiple players, or non-player characters, to pick up items at the
396407
same time, you may introduce a problem when two characters attempt try
@@ -477,6 +488,10 @@ In this code, you:
477488
*in his own inventory*, update the character's inventory
478489
representation of the container.
479490

491+
.. I think that the item documents should be immutable, describing types of times in the game.
492+
Instances of items exists either in a user or location documents.
493+
A backpack can contain other items, but if player picks up backpack he just get the contained items in his inventory.
494+
480495
Moving the Character to a Different Room
481496
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
482497

@@ -507,6 +522,8 @@ location:
507522
This operation updates the old room, the new room, and the character
508523
document to reflect the new state.
509524

525+
.. this should not change the location document using earlier changes
526+
510527
Buying an Item
511528
~~~~~~~~~~~~~~
512529

draft/use-cases/serving-ads.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ The schema for storing available ads consists of a single collection,
7575
... ]
7676
}
7777

78+
.. kind of confusing to call this collection "ad.zone", esp since there is only 1 and zone is just property
79+
7880
For each (``site``, ``zone``) combination you'll store a list of ads,
7981
sorted by their ``ecpm`` values.
8082

@@ -102,6 +104,10 @@ maximize the ad network's profits. This query resembles the following:
102104
ecpm, ad_group = ecpm_groups.next()
103105
return choice(list(ad_group))
104106

107+
.. should be noted that here the list of ads get sorted client side for every call.
108+
also full list gets pulled every time.
109+
In case that the list is long, would be better to normalize, then use index on {site, zone, ecpm}
110+
105111
Indexing
106112
````````
107113

@@ -225,6 +231,11 @@ This schema:
225231
timestamp. This facilitates rapid lookups of a stream of a
226232
particular type of event.
227233

234+
.. probably should warn that storing impressions and clicks within user document can backfire.
235+
Could grow very large, e.g. if it's a bot, and past 1000 will start slowing down db.
236+
A more robust solution would keep each impression with its possible click in a separate document.
237+
Could be in a capped collection if impressions do not need to be kept for long.
238+
228239
Choosing an Ad to Serve
229240
~~~~~~~~~~~~~~~~~~~~~~~
230241

@@ -411,3 +422,7 @@ customize the value of some keywords, but this is beyond the scope of
411422
this document. Because the ad service must sort all ads at display
412423
time, you may find performance issues if you if there are a large
413424
number of ads competing for the same display slot.
425+
426+
.. here the processing will be done client side for every request.
427+
This can become very expensive if a page gets hit a lot and has many possible ads.
428+
Again here if normalize each ad, can use index on { site, zone, keywords }

draft/use-cases/social-networking-updates-and-profiles.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ Consider the following features of this schema:
112112
sub-document, so that you may iterate the schema can evolve as
113113
necessary without affecting other fields.
114114

115+
.. storing followers in a list would not work well at all in case like twitter, it would grow way too large.
116+
should only store people that user is following, and index that to get follower list of a user.
117+
Also could use a mapping table for further flexibility in relationship.
118+
115119
Posts, of various types, reside in the ``social.post`` collection:
116120

117121
.. code-block:: javascript
@@ -250,6 +254,11 @@ Consider the following features of this schema:
250254
certain number of comments because the :operator:`$size` query
251255
operator does not allow inequality comparisons.
252256

257+
.. not sure this collection is useful, instead just use the post collection.
258+
Posts should have an index on {user, time} and hence it is efficient to retrieve the wall.
259+
Also wall may be scrolled down to get further items.
260+
Dont think it's worth updating this document every time a user posts.
261+
253262
The second dependent collection is is ``social.news``, which collects
254263
posts from people the user follows. These documents duplicate
255264
information from the documents in the ``social.wall`` collection:
@@ -263,11 +272,16 @@ information from the documents in the ``social.wall`` collection:
263272
posts: [ ... ]
264273
}
265274

275+
.. This is probably too expensive.
276+
If someone is followed by 1000+ people, that's a lot of documents to write to.
277+
Instead system should use a $in query with people that user is following, sorted by time, with a limit.
278+
This query is actually slow today but got improved a lot in 2.2 and there are good workarounds with 2.0.
279+
266280
Operations
267281
----------
268282

269283
The data model presented above optimizes for read performance at the
270-
possible expense of write performance. To As a result, you should ideally
284+
possible expense of write performance. As a result, you should ideally
271285
provide a queueing system for processing updates which may take longer
272286
than your desired web request latency.
273287

0 commit comments

Comments
 (0)