Synchronous vs Asynchronous Events

May 17, 2024

Synchronous vs Asynchronous Events

Key Concepts

  • Synchronous Events:
    • Real-time interaction
    • Both parties must be present simultaneously
    • Example: Phone calls
  • Asynchronous Events:
    • Time-independent interaction
    • Parties do not need to be present at the same time
    • Example: Texting, ordering a package from Amazon

Detailed Comparisons

Synchronous Events

  • Must occur at the same time
  • Direct and immediate communication
  • Example: Phone call
    • Both persons need to be on the call simultaneously
    • Immediate response required

Asynchronous Events

  • Can occur at different times
  • Delayed communication
  • Examples:
    • Texting: Message sent and can be read/responded to later
    • Amazon Package: Order placed, and delivery happens later
  • No immediate response is required

Application in Computing

  • Main Thread Execution: Execute instructions sequentially
  • Parallel Service Execution: Service operates independently, returns results later

Database Example

Synchronous Database (Tiny DB)

  • Stores data locally
  • Immediate data retrieval
  • Code block features:
    • Puzzle-like appendage indicating immediate data return
  • Data is accessible instantaneously

Asynchronous Database (Cloud DB)

  • Stores data on the web
  • Delayed data retrieval
  • Code block features:
    • No puzzle-like appendage
    • Utilizes event blocks:
      • GotValue Event: Triggered after data is retrieved
      • DataChanged Event: Triggered whenever data changes
  • Facilitates easier data sharing among multiple users

Pros and Cons

Cloud Database

  • Longer data retrieval times
  • Advantage: Easier data sharing among users

Tiny DB

  • Faster data access (local storage)
  • Limited to individual devices