Course contentsShow
← System Design
Lesson 1559 of 1,91938. Real-World System: PastebinFree lesson

Write Path: Synchronous vs Asynchronous Storage

Write metadata synchronously to DB for immediate consistency; optionally async-upload large content to S3.

Write Path: Synchronous vs Asynchronous Storage

What you'll learn: How to balance consistency and performance by writing metadata synchronously while optionally uploading paste content asynchronously.

When a user creates a paste in Pastebin, you need to store two distinct pieces: metadata (URL, expiration, timestamp) and content (the actual paste text). The key architectural decision is when and how to persist each.

The Synchronous Metadata Write

Your metadata must be written synchronously to the relational database before returning success to the user. This ensures:

  • Immediate consistency: The paste URL is instantly valid
  • Reliable ID reservation: No race conditions on duplicate paste keys
  • Accurate expiration tracking: TTL policies work from the moment of creation

Think of this like checking into a hotel: you must get your room key from the front desk before you can claim "I have a room here."

The Asynchronous Content Upload

For large paste content, you can optionally upload to object storage (S3) asynchronously:

  1. Write metadata to DB (with status: processing)
  2. Return success to user immediately
  3. Background worker uploads content to S3
  4. Update metadata status to complete

This pattern works when:

  • Content is large (>1MB)
  • Upload latency would hurt user experience
  • You have retry mechanisms for failed uploads

The Tradeoff

Synchronous writes guarantee immediate consistency but may increase response time. Asynchronous uploads improve perceived performance but introduce eventual consistency—users might briefly see "processing" states.

Key Takeaway: Write metadata synchronously to your database for immediate consistency and reliable ID generation; use asynchronous uploads to object storage only when content size justifies the complexity of eventual consistency.