CAP Theorem, ACID, and Choosing Between SQL and NoSQL in .NET with AWS and Azure

Posted by Rodrigo Castro on August 12, 2025

Introduction

Choosing the right database is one of the most critical architectural decisions when building modern .NET applications (or any application). Whether you deploy to AWS or Azure, your database will influence scalability, consistency, performance, and even development complexity. In cloud-native environments, CAP theorem and ACID principles are key to understanding when to use SQL and when to use NoSQL.

Understanding the CAP Theorem

The CAP Theorem states that in a distributed system, you can only guarantee two out of three properties at any given time:

  • Consistency (C): Every read receives the most recent write or an error.
  • Availability (A): Every request receives a response, even if it is not the most recent data.
  • Partition Tolerance (P): The system continues to operate despite network partitions.

Real-world analogy

Imagine a distributed online store:

  • If the store prioritizes Consistency and Partition tolerance (CP), during a network split, some customers may experience errors instead of stale data.
  • If it prioritizes Availability and Partition tolerance (AP), the store stays up but customers might see outdated inventory.
  • If it prioritizes Consistency and Availability (CA), it works only as long as there are no network partitions which is unrealistic in cloud systems.

In practice, all distributed databases must tolerate partitions, so the real choice is between C and A.

Understanding ACID

ACID is a set of properties that ensure reliable transactions in databases:

  1. Atomicity: Transactions are all-or-nothing.
  2. Consistency: Transactions bring the database from one valid state to another.
  3. Isolation: Concurrent transactions do not interfere with each other.
  4. Durability: Once committed, data remains saved even after failures.

ACID vs BASE

  • ACID: Strong consistency, perfect for financial transactions.
  • BASE (Basically Available, Soft state, Eventually consistent): Often used by NoSQL systems for scalability and availability.

SQL vs NoSQL Decision Factors

Factor SQL Databases NoSQL Databases
Data Structure Fixed schema (tables, columns) Flexible schema (documents, key-value, graphs)
Consistency Model Strong (ACID) Often eventual (BASE)
Scaling Vertical (bigger machines) Horizontal (more machines)
Query Language SQL Varies (JSON queries, APIs)
Best For Financial systems, ERP, CRM Event logs, IoT, social media, content management

AWS and Azure Database Options

AWS

  • SQL: Amazon RDS (SQL Server, MySQL, PostgreSQL), Amazon Aurora
  • NoSQL: Amazon DynamoDB (AP system), Amazon DocumentDB (CP system), Amazon Keyspaces (Apache Cassandra)

Azure

  • SQL: Azure SQL Database, Azure Database for PostgreSQL/MySQL
  • NoSQL: Azure Cosmos DB (multi-model, tunable consistency), Azure Table Storage

Integrating with .NET

SQL Example (Entity Framework Core with Azure SQL)

1
2
3
4
using var context = new AppDbContext();
var order = new Order { ProductId = 1, Quantity = 5 };
context.Orders.Add(order);
await context.SaveChangesAsync();

NoSQL Example (DynamoDB with AWS SDK for .NET)

1
2
3
4
5
6
7
8
9
10
11
12
var client = new AmazonDynamoDBClient();
var request = new PutItemRequest
{
    TableName = "Orders",
    Item = new Dictionary<string, AttributeValue>
    {
        { "OrderId", new AttributeValue { S = Guid.NewGuid().ToString() } },
        { "ProductId", new AttributeValue { N = "1" } },
        { "Quantity", new AttributeValue { N = "5" } }
    }
};
await client.PutItemAsync(request);

Please note that there are custom Entity Framework providers available for certain NoSQL data sources, enabling developers to use EF with document, key-value, or graph databases while still taking advantage of EF’s LINQ queries and change tracking.

Decision Matrix

Requirement Recommended Reason
Financial transactions SQL + ACID Strong consistency & reliability
High-volume event logging NoSQL (AP) Scalability & availability
IoT telemetry ingestion NoSQL (eventual consistency) High write throughput
Inventory systems SQL or Cosmos DB (strong consistency) Data accuracy is critical
Social media feed NoSQL (eventual consistency) Low latency, high availability

Financial transactions For systems like banking apps, payment gateways, or order processing platforms, every transaction must be processed exactly once and remain consistent even during failures. For example, transferring money between accounts should never result in partial updates or double withdrawals. SQL databases with ACID guarantees ensure these operations remain atomic and consistent, making them the preferred choice.

High-volume event logging Applications that log millions of events per day, such as API access logs or user activity tracking, require low-latency writes and massive scalability. In this case, the occasional delay in data visibility is acceptable as long as the system never goes down. NoSQL solutions like Amazon DynamoDB or Azure Table Storage are ideal here because they prioritize availability and can scale horizontally.

IoT telemetry ingestion IoT platforms ingest large amounts of sensor data from devices such as smart meters, wearables, or industrial machinery. Data arrives continuously, often in bursts, and the priority is capturing it in near real time, even if some readings become visible to queries a few seconds later. NoSQL databases with eventual consistency, such as Azure Cosmos DB or AWS Timestream, are well-suited for this workload.

Inventory systems Retail and manufacturing businesses need up-to-date stock counts to avoid overselling and to manage replenishment efficiently. For example, if a product has only one unit left, two customers must not be able to buy it simultaneously. SQL databases or NoSQL systems with strong consistency (like Cosmos DB configured for strong consistency) are appropriate to maintain data accuracy across distributed systems.

Social media feed Platforms like Twitter or LinkedIn must deliver updates quickly to millions of users worldwide. A small delay in seeing the most recent posts is acceptable if it improves responsiveness and uptime. NoSQL databases optimized for high read throughput, such as DynamoDB or Cassandra, excel in these scenarios due to their ability to handle massive concurrent reads and writes with low latency.

Conclusion

There is no one-size-fits-all database. Modern .NET solutions often mix SQL for transactional workloads and NoSQL for high-volume, scalable workloads. AWS and Azure both provide rich ecosystems to support either choice, but understanding CAP theorem and ACID principles will ensure your architecture is aligned with your business requirements.