title
stringlengths
3
46
content
stringlengths
0
1.6k
12:102
Multi-tenant applications are not rare in the cloud since all applications that offer the same services to several different users are often implemented as multi-tenant applications, where each tenant corresponds to a user subscription. Accordingly, relational databases, such as Azure SQL Server, are conceived to work in the cloud and usually offer sharding options for multi-tenant applications. Typically, sharding is not a cloud service and must be defined with database engine commands. Here, we will not describe how to define shards with Azure SQL Server, but the Further reading section contains a link to the official Microsoft documentation. The following table presents the pros and cons of each database approach:
12:103
12:104
12:105
12:106
12:107
Subject
12:108
12:109
12:110
SQL
12:111
12:112
12:113
NoSQL document-oriented DB
12:114
12:115
12:116
12:117
12:118
Schema
12:119
12:120
12:121
Easy to deal with in well-structured schemas. Today, it is possible to design hybrid solutions with JSON/XML columns to store unstructured data.
12:122
12:123
12:124
Preferred when data has almost no predefined structure.
12:125
12:126
12:127
12:128
12:129
Performance
12:130
12:131
12:132
In general, bad performance in distributed environments.
12:133
12:134
12:135
In general, good performance for reading and writing distributed data.
12:136
12:137
12:138
12:139
12:140
Language
12:141
12:142
12:143
Declarative to query and update data, standard.
12:144
12:145
12:146
Procedural to query and update operations.
12:147
12:148
12:149
12:150
12:151
Consistency
12:152
12:153
12:154
Strong use of foreign keys.
12:155
12:156
12:157
Weak and left to the developer's decision. All related objects that are likely to be processed together into a single entry.
12:158
12:159
12:160
12:161
12:162
Transactions
12:163
12:164
12:165
Supported.
12:166
12:167
12:168
By default, they are not supported.
12:169
12:170
12:171
12:172
12:173
Scale
12:174
12:175
12:176
Vertically upgrading hardware.
12:177
12:178
12:179
Horizontally with data sharding.
12:180
12:181
12:182
12:183
12:184
Table 12.1: Pros and cons for each database approach
12:185
In conclusion, relational databases offer a pure, logical view of data that is independent of the way they are stored and use declarative language to query and update them. This simplifies development and system maintenance, but it may cause performance issues in a distributed environment that requires write scale-out. It is also worth noting that tools like Entity Framework, presented in Chapter 13, Interacting with Data in C# – Entity Framework Core, help in bridging the gap between objects and relational data, making development more intuitive for relational databases.
12:186
In NoSQL document-oriented databases, you must handle more details about how to store data, as well as some procedural details for all the update and query operations, manually, but this allows you to optimize performance in distributed environments that require both read and write scale-out. On the flip side, working with NoSQL data, especially when it involves deserializing formats like JSON or XML, can be tricky. It often requires careful mapping to ensure data integrity, which can be both challenging and error-prone. In the next section, we will look at Azure Cosmos DB, the main Azure NoSQL offering, which, fortunately, can be integrated with Entity Framework for a more streamlined development experience.
12:187
Azure Cosmos DB – an opportunity to manage a multi-continental database
12:188
Azure Cosmos DB is Azure’s main NoSQL offering. Azure Cosmos DB has its own interface that is a subset of SQL, but it can be configured with a MongoDB interface, a Table API, or a Cassandra API. It can also be configured as a graph data model that can be queried with Gremlin.
12:189
12:190
You can find further details about Cosmos DB in the official documentation: https://docs.microsoft.com/en-us/azure/cosmos-db/.
12:191
12:192
Cosmos DB allows replication for fault tolerance and read scale-out, and replicas can be distributed geographically to optimize communication performance. Moreover, you can specify which data center all the replicas are placed in. The user also has the option to write-enable all the replicas so that writes are immediately available in the geographical area where they are done. Write scale-up is achieved with sharding, which the user can configure by defining which properties to use as shard keys.
12:193
Creating an Azure Cosmos DB account
12:194
You can define a Cosmos DB account by typing Cosmos DB into the Azure portal search bar and clicking + Create. The following page will appear:
12:195
12:196
Figure 12.5: Creating an Azure Cosmos DB account
12:197
For instance, if you select the Core (SQL) option, the account name you choose is used in the resource URI as {account_name}.documents.azure.com. Then, you can decide which location the main database will be placed in and the capacity mode. You can check more information about the capacity modes available at https://docs.microsoft.com/en-us/azure/cosmos-db/throughput-serverless.
12:198
Microsoft keeps improving many of its Azure services. The best way to keep updated about new features of any Azure component is by checking its documentation from time to time.
12:199
On the Global Distribution tab, the Multi-region Writes toggle lets you enable writes on geographically distributed replicas. If you do not do this, all write operations will be routed to the main location. Finally, you may also define network connectivity, backup policies, and encryption during the creation process.
12:200
Creating an Azure Cosmos DB container
12:201
Once you have created your Azure Cosmos DB – Core SQL account, select Data Explorer to create your databases and containers inside of them. A container is the unit of scalability both for provisioned throughput and storage, available when you decide by provisioned throughput capacity mode.