Reputation: 673
Document structure
-user
- firstName
- lastName
...
- session
- table1
- filters, searches, states etc
- table2
- filters, searches, states etc
...
Question : Should I keep the session data in the user document or in a separate document?
If a user logs in, we query the entire document:
query = 'find the user... return u
If a user logs out, we save the user, including its session state
If a userlist is shown, we query only the doc fields needed:
query = 'for u in users.... return
{firstName: u.firstName, lastName: u.lastName}
Thoughts: Although we query only the data we need, does the size of the document impact DB-performance in the background? Like does Arangodb fetch the entire document in the background, before returning only part of it? Or maybe any other server processes that are impacted by bigger doc sizes?
Upvotes: 1
Views: 584
Reputation: 96
Session data needs to be associated with user, so it might makes more sense to store it on user vertex, else you can store on a separate vertex and make reference to it (edges in graph). For users to be served often based on their requests, caching user data might prove effective rather than querying db every now.
If user is active, you can place session in an intermediate storage like cache for faster access and you can write it later to db once when he logs out or at specified time intervals.
In case of ever increasing size of documents, you could consider only recent n
number of sessions (which depends on your application domain and business requirements), as users preferences ever changes, to contain per-document size.
Yes, in case of arango query, entire documents are fetched before indexes and other optimizations are applied by query optimizer, it makes an impact on performance.
Upvotes: 1
Reputation: 711
ArangoDB fetches full documents. You should avoid large documents for best performance. You can see here an example of how a document is received from the RocksDB key-value-store
Upvotes: 2