Prepare a project-specific answer covering the why, the partition key decision, and honest drawbacks. Why Cosmos DB was chosen (typical reasons) - Very low-latency reads and writes at scale with automatic, elastic scaling and SLAs for availability and latency. - Flexible JSON schema: documents such as product catalogs, user profiles, IoT readings or orders with varying attributes fit naturally. - Global distribution and multi-region writes for users in several regions. - Automatic indexing of every property and built-in change feed for event-driven processing (updating search indexes, materialized views, notifications). - Fully managed — no patching or capacity planning of servers. Partition key choice — example "Orders were partitioned by /customerId." Reasoning: - Most queries were "orders for this customer" or "this order of this customer", so they hit a single partition — cheap point reads and single-partition queries. - High cardinality (millions of customers) spreads storage and throughput evenly, avoiding hot partitions. - Transactional batches and stored procedures work within one logical partition, which matched customer-level operations. Things we checked: a single logical partition is limited to 20 GB, so we avoided keys where one value could grow too large; for very large tenants, hierarchical partition keys (tenantId then userId) or a synthetic key (customerId + month) solve this. We avoided low-cardinality keys like status or country, and keys like timestamp that create hot partitions for writes. Disadvantages of Cosmos DB - Cost can be high and less predictable: Request Units are charged for throughput, and inefficient or cross-partition queries become expensive. Requires capacity planning (manual, autoscale or serverless). - The partition key cannot be changed in place; changing it requires migrating to a new container. - Limited relational features: no joins across documents and limited aggregation compared with SQL; data often needs denormalisation and duplication. - Transactions only within one logical partition. - 429 throttling when exceeding provisioned RUs, which the application must handle (the SDK retries). - Maximum item size (2 MB) and per-partition limits. - Learning curve for data modelling, consistency levels and RU optimisation. A mature answer mentions mitigation: monitoring RU consumption, using point reads, tuning indexing policies to exclude unused paths, and choosing session consistency as a good default.
Ravindra Wadile · · 0 likes