Amazon iconAmazonSep 9, 2026 ~7 min source read

Build a high-concurrency async Python app with Tortoise ORM and Amazon Aurora DSQL

A practical guide showing how to adapt Tortoise ORM for Aurora DSQL: UUID primary keys, IAM-authenticated asyncpg connections, single-statement DDL, and optimistic concurrency control with async retry.

Building async Python applications with Tortoise ORM and Amazon Aurora DSQL

Share this story

Send the public story page.

Useful takeaways from this story.

Use UUID v4 primary keys and UUID-based relationships to avoid cross-node coordination in Aurora DSQL.

Execute DDL statements individually (no multi-statement DDL transactions) and run OCC-protected writes behind async retry with exponential backoff and jitter.

Tortoise ORM’s async-native API pairs with Aurora DSQL’s serverless model to support high-concurrency workloads when you apply these adaptations.

# Why this combination Tortoise ORM is an async-native Python ORM with a Django-like model API and an asyncpg backend. Aurora DSQL is a serverless, distributed PostgreSQL-compatible engine where connection efficiency and concurrency matter. Together they form a stack suited for high-concurrency async applications—provided you make a few concrete changes to how you model data, open connections, apply schema changes, and handle concurrent writes.

# Core adaptations you must make The article demonstrates these four practical adaptations used in a sample rideshare application (riders, drivers, rides, payments):

  • UUID primary keys: Use UUID v4 for primary keys to avoid coordinated ID generation across Aurora's distributed architecture. Tortoise supports fields.UUIDField(primary_key=True, default=uuid.uuid4).
  • IAM-authenticated asyncpg connections: Replace static passwords with short-lived IAM tokens generated by boto3's DSQL client. Initialize Tortoise with asyncpg using the IAM token as the password and TLS enabled. Patch asyncpg's connection reset so the connection pool works with IAM token semantics.
  • Individual DDL execution: Aurora DSQL does not accept multiple DDL statements in one transaction. Run schema creation and other DDL statements one at a time through a raw asyncpg connection rather than batching DDL into a single transaction.

# How the sample rideshare app flows The sample models riders, drivers, rides, and payments as Tortoise ORM models mapped to Aurora tables. At runtime:

  1. The app generates an IAM authentication token using boto3's DSQL client.
  2. It patches asyncpg's connection reset behavior to make pooling compatible with IAM tokens.
  3. Tortoise ORM initializes using the asyncpg backend with TLS and the IAM token as the password.
  4. Schema creation executes each DDL statement individually through a raw asyncpg connection.
  5. App code runs async CRUD flows: creating users, requesting rides, completing trips, and processing payments. Writes that can conflict use OCC retry with exponential backoff and jitter.

# Practical implications for engineers

# When to follow these patterns Apply these changes when building async, high-concurrency Python services that connect directly to Aurora DSQL via asyncpg and when you need serverless scaling, short-lived credentials, and efficient use of async coroutines. If you rely on integer sequences or identity columns for IDs, Aurora DSQL still supports sequences and identity with CACHE, but the sample recommends UUID v4 for distributed-friendly ID generation.

# Quick checklist before production

  • Switch primary keys to fields.UUIDField(primary_key=True) where cross-node generation matters.
  • Patch asyncpg connection reset so connection pools remain stable with IAM tokens.
  • Run DDL statements individually during schema creation/migrations.
  • Add OCC detection and async retry with exponential backoff and jitter for conflicting writes.

# Bottom line Tortoise ORM and Aurora DSQL work together for async Python services if you adapt model keys, connection authentication, DDL execution, and write concurrency handling. The sample rideshare app provides concrete patterns you can reuse for similar high-concurrency domains.

More context around this story.

Loading more related stories...

Keep reading in the app

Open the app view to save this story, compare related coverage, and continue from the same source.

Open in app