Good Pattern: Flat Model
Nesting multiple MAP objects in a single document may result in slow sync performance. So, rather than using a single document to encode a large dataset, use a series of smaller documents, which are inexpensive in terms of storage and processing resources.
The preference for a flatter data model, in which you utilize smaller documents rather than nesting MAP objects, is due to Ditto considering collections as inexpensive in terms of storage and processing resources.
Ditto uses a combination of the collection name and the document ID to sync and query documents, and collections serve as an index for a set of related documents. You can use this index to establish foreign-key relationships between them by referencing the document ID. For more information, see Relationships.
For example, consider a people collection and a cars collection:
![Document image Document image](https://images.archbee.com/qoRkNxW5fJ81r_NqVpc8C/e8CtCZ1NykU9J2ct0YhSx_goodpatternschema.png?format=webp)
In the previous example, each car has an owner — represented by the _id.ownerId field — which relates to the person's document ID.
Since the document _id is immutable, only use the flat model in situations where you have static identifiers within your foreign-key relationship. If you use the flat model
In the people collection:
In the cars collection: