Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

will document ids like {year}-Q{n} cause performance problems?

The Firestore docs "Best Practices" section says:

Document IDs

Do not use monotonically increasing document IDs such as:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Customer1, Customer2, Customer3, …

Product 1, Product 2, Product 3, …

I’d like to store historical data in a collection with one document per quarter, and use document ids like 2022-Q1, 2022-Q2, etc.

These aren’t strictly monotonically increasing because the year number changes after 4 quarters. But they’re still lexicographically close. Will this cause performance problems?

My data goes about back 50 years so there will be around 200 documents.

>Solution :

200 documents with any IDs are not going to cause any performance problems. That is a very small amount of data from Firestore’s point of view.

The recommendation that you’re citing from the docs has to do with situations where documents are added very rapidly to a collection. If you read on, it says "Such sequential IDs can lead to hotspots that impact latency". If you read about hotspotting, that is not your situation, so you don’t have to worry about it.

Aside, it’s generally not a good idea to put data in your document IDs. That can cause problems for you later. Data belongs in document fields. You’re generally better off using Firestore’s randomly generated IDs unless you already have a source of unique IDs.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading