Understanding Couchbase Lite Data Model


#1

We’ve a Point of Sale mobile app. On average, our users record 150 transactions per day (mobile payments).

We’re discussing about our Data Model and the main question is, Should we create one document per transaction or append transaction within a particular document, for example per day? Our biggest concern is about performance (app speed) for creating and query documents.

Given this use case: there is a “Sales Report” that shows all transactions (date, amount, ticket id, etc…) sort by timestamp. The user can changes the dates range.

Scenario 1: one document per transaction

  • I’ll work with 150 documents per day (about 1,000 doc for a whole week). The mapping function will take longer, at least the first time if there is a lot documents without index.
  • Easy to get the transactions details.

Scenario 2: one document per day with all transaction appended within an array.

  • I’ll work with a few documents.
  • More complex to I will need more logic to push and pull transactions.
  • it’ll consume more data traffic. Everytime I add a new transactions, the whole document will be sync.
  • It seems to be faster for query because I just work with a few documents?

Given your experience, what scenario do you recommend? Any suggestion?

Thanks


#2

Scenario 1 might take a little bit longer to index, but probably not much. The total amount of JSON to be parsed is about the same, and the number of index rows emitted would be the same, so it’s just the overhead of reading documents.

Scenario 2 won’t be any faster for querying. Your indexes would probably be the same for either scenario, since you probably want a row (key/value pair) for every transaction.

I think Scenario 1 is a better choice.