Tutorials Logic, IN info@tutorialslogic.com

Azure Databases: Azure SQL, PostgreSQL, Cosmos DB, and Cache

Choose From Access Patterns

Azure offers managed relational, document, key-value, cache, and analytics data services. Selection begins with data shape, query patterns, consistency, scale, and recovery needs.

Azure SQL Database and managed open-source engines support relational workloads. Cosmos DB supports globally distributed NoSQL models, while managed cache reduces repeated reads when cached data can be rebuilt.

Managed databases reduce infrastructure work but still require private access, credential design, capacity planning, backups, monitoring, and tested recovery.

Use relational services when transactions, joins, constraints, and SQL are central. Consider Cosmos DB when partitioned access patterns and global distribution are explicit requirements.

  • List important queries before choosing the engine.
  • Select a Cosmos DB partition key from data distribution and request patterns.
  • Treat cache as an acceleration layer, not the only copy of critical data.

Identity and Private Connectivity

Use Microsoft Entra authentication where supported, store remaining secrets in Key Vault, and connect through private endpoints or delegated subnets according to the service.

  • Avoid public firewall exceptions for developer convenience.
  • Encrypt client connections.
  • Use connection pooling and protect database connection limits.

Availability, Backup, and Recovery

Define required availability, recovery point, and recovery time before selecting redundancy or geo-replication. Restore backups into an isolated environment and validate application-level correctness.

  • Know the difference between replicas, failover groups, and backups.
  • Protect retention settings from accidental reduction.
  • Document DNS or connection changes during failover.

Performance and Capacity

Monitor latency, CPU or request units, storage, connections, locks, throttling, and failed requests. Pair platform metrics with query plans and application traces.

  • Load test with realistic data volume and concurrency.
  • Review indexes and expensive queries before scaling blindly.
  • Include backup, geo-replication, and egress in cost estimates.

Database Access Ledger

List required reads, writes, joins, filters, ordering, transactions, consistency, throughput, item size, latency, retention, growth, and regional behavior before selecting a service. Include backup, export, audit, and deletion. A managed product name cannot compensate for a data model that does not fit the application operations.

Azure SQL and Azure Database for PostgreSQL provide relational engines with constraints and transactions. Azure Cosmos DB supports distributed data models and APIs with partitioned throughput and selectable consistency. Azure Managed Redis provides in-memory data structures and caching behavior. Each moves different infrastructure work to Microsoft and leaves different application responsibilities.

Record rejected options, engine compatibility, migration tooling, operator skill, lock-in, and recovery. Benchmark production-like data and concurrency. Database choice is an application contract that affects code, cost, and failure for years.

  • Write access patterns before selecting the engine.
  • State transaction and consistency requirements.
  • Include administrative and recovery operations.
  • Benchmark representative volume and concurrency.

Azure SQL Service Model

Azure SQL Database provides managed SQL Server database capabilities with purchasing and service tiers that differ in compute, storage, I/O, scaling, replicas, and recovery. Azure SQL Managed Instance offers broader instance compatibility for migrations with instance-level features. Verify feature and version compatibility rather than assuming every SQL Server workload fits either service unchanged.

Choose provisioned or serverless compute and General Purpose, Business Critical, Hyperscale, or current supported alternatives from workload behavior. The tier affects architecture, not only price. Test connection limits, temp workload, transaction log behavior, read scale, maintenance, and scale operations with production-like queries.

Use Entra authentication where it fits, private endpoints or controlled firewall paths, TLS validation, and contained least-privilege database users. Add transient-fault retry at safe transaction boundaries. Zone and geo-redundancy improve availability, while backups and point-in-time restore protect logical error.

  • Check SQL Server feature compatibility before migration.
  • Choose tier from measured I/O and recovery needs.
  • Keep the database private and identities narrow.
  • Test failover-aware connection behavior.

PostgreSQL Flexible Server

Azure Database for PostgreSQL Flexible Server manages infrastructure, backups, patch workflow, and supported high-availability configurations while the customer owns schema, queries, extensions, roles, connections, and application compatibility. Verify extension, collation, parameter, major version, and Region support before migration.

Zone-redundant and same-zone high availability use a synchronously replicated standby under the service model, but availability is not backup. A standby can receive the same accidental deletion. Use point-in-time restore for logical error and test it into a separate server before promoting or extracting data.

Bound application connection pools across the whole fleet, reserve operational capacity, and consider an appropriate pooler. Monitor CPU, memory, storage, I/O, connections, transaction age, locks, query latency, replication, backup, and maintenance. Test planned and unplanned failover and application reconnection.

  • Verify extensions and major-version compatibility.
  • Distinguish high availability from point-in-time recovery.
  • Calculate total connection demand across instances.
  • Exercise failover and restore separately.

Cosmos DB Partition Contract

Azure Cosmos DB distributes items by a partition key into logical partitions that map to service-managed physical partitions. Choose a high-cardinality key that distributes storage and request units while appearing in common queries. A hot key can constrain one logical partition even when total account capacity looks sufficient.

Model request-unit cost for point reads, queries, writes, indexing, and cross-partition work. Select indexing paths and throughput mode from measured access. Transactions and stored procedures have partition boundaries under the selected API. A broad cross-partition query may work in a lab but scale poorly in latency and cost.

Choose strong, bounded staleness, session, consistent prefix, or eventual consistency from application semantics and regional design. Session consistency depends on session-token handling for read-your-write behavior. Multi-region writes introduce conflict and routing decisions that must be tested during failover.

  • Choose partition key from query and write distribution.
  • Measure request units for real operations.
  • State consistency behavior visible to users.
  • Test hot partitions and regional failover.

Azure Managed Redis Boundary

Use Azure Managed Redis for caches and supported in-memory data patterns whose loss, eviction, and staleness are understood. Azure Cache for Redis has a retirement path, so new and existing designs must follow current Microsoft migration guidance rather than treating old tiers as the long-term default.

Define source of truth, cache-aside or write strategy, TTL, invalidation, key ownership, serialization version, and stampede protection. Add jitter to synchronized expiry and prevent an empty cache from overwhelming the database. A successful cache write is not a durable business commit unless the architecture explicitly makes it one.

Use private networking, Entra or supported authentication, TLS, and secret rotation according to the selected service. Monitor hit ratio, latency, memory, eviction, connections, server load, replication, and source impact. Exercise cache flush, node failover, stale values, and migration to a new instance.

  • Follow the current Azure Cache for Redis retirement guidance.
  • Name the durable source of truth.
  • Protect the source from cache stampede.
  • Test complete cache loss and migration.

Migration and Recovery Proof

Use versioned expand-and-contract schema changes for rolling application releases. Estimate lock, rewrite, index build, and backfill cost against production-like data. Keep backfills resumable and rate-limited, and define whether rollback reverses data, stops a writer, or rolls forward with correction.

Place database endpoints on private paths where required, validate TLS, manage credentials or Entra identities centrally, and separate deployment from runtime privilege. Plan DNS and connection retry for failover without retrying an uncertain non-idempotent transaction blindly.

Map every data store to RPO and RTO, backup retention, key ownership, regional copy, and restore owner. Restore into isolation and verify schema, users, network, integrity, and real application reads and writes. Monitor performance and recovery evidence continuously; a completed backup job is not proof that the business can recover.

  • Keep migrations compatible with mixed application versions.
  • Make large backfills resumable and bounded.
  • Define transaction behavior after ambiguous failure.
  • Restore through the application path.

Database Service Lifecycle

Track engine major versions, service-tier changes, retired SKUs, authentication methods, network features, drivers, extensions, backup behavior, and cache retirement notices. A managed database reduces infrastructure maintenance but does not make an unsupported application driver or extension compatible automatically.

Test upgrades and migrations with production-like schema, statistics, workload, connection pools, failover, private DNS, encryption, and restore. Keep a rollback or forward-fix plan for data changes, and finish the migration before the service deadline removes a safe rehearsal window.

  • Maintain an engine and driver compatibility matrix.
  • Rehearse upgrade, failover, and restore together.

Connection Resilience Contract

Set connection, command, and transaction timeouts from the outer request deadline. Retry transient connection or availability failures with bounded jitter only when the operation is safe; never replay an ambiguous committed write without an idempotency or reconciliation rule. Pool limits must account for every app replica, function host, worker, and administrative reserve.

During failover, DNS, existing sockets, transactions, session state, and prepared work can behave differently. Test driver reconnection against Azure SQL, PostgreSQL, Cosmos DB, or Redis according to the selected service. Record which errors are transient, which require rollback, and what the user sees while the client recovers.

  • Budget nested timeouts from the caller inward.
  • Protect ambiguous writes from duplicate effects.
  • Calculate pool capacity across the whole fleet.
  • Test the real driver during service failover.

Azure Database Examples

Simple SQL Table

Simple SQL Table
CREATE TABLE Orders (
    Id INT IDENTITY PRIMARY KEY,
    CustomerEmail NVARCHAR(255) NOT NULL,
    TotalAmount DECIMAL(10,2) NOT NULL,
    CreatedAt DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME()
);



CREATE INDEX IX_Orders_CustomerEmail ON Orders(CustomerEmail);

Prove Point-in-Time Recovery

A faulty migration removes rows from a production database.

Prove Point-in-Time Recovery
Constraints: The recovery point objective is ten minutes and the original server must remain available for comparison.
Decision: Restore to a new database just before the migration, validate invariants, then choose a controlled cutover or selective repair.
Verification: Row counts, checksums, permissions, and application smoke tests pass within the recovery objective.
Failure test: Restore from an older point and show the validation rejects missing legitimate transactions.
Output
Expected evidence: Row counts, checksums, permissions, and application smoke tests pass within the recovery objective.
  • This is a worked engineering decision, so the result is operational evidence rather than terminal output.
Before you move on

Azure Databases: Azure SQL, PostgreSQL, Cosmos DB, and Cache Mastery Check

5 checks
  • The engine matches documented data and query patterns.
  • The application uses private connectivity and managed identity where supported.
  • Connection and throughput limits are understood.
  • Backup restoration and failover have been exercised.
  • Performance monitoring covers both service and query behavior.
Browse Free Tutorials

Explore 500+ free tutorials across 20+ languages and frameworks.