Introduction to Synchronous and Asynchronous Processing

March 15, 2021

Alisdair Broshar

Alisdair Broshar
@AlisdairBroshar

Synchronous and asynchronous, also known as sync and async, are two types of programming models. At an abstract level, programming models define how software is designed and executed.

The basic programming models are synchronous, but asynchronous models are critical for performance reasons and to more efficiently use computing resources. Programming languages usually have built-in primitives to deal with asynchronous programming.

Knowing how these two models differ is vital when building APIs, creating event-based architectures, and considering how to handle long-running tasks. In this blog post, we review the differences between these models, namely what it looks like when they run and their ideal use cases.

This blog post builds off our previous event-driven architectures blog post, Understanding Event-Driven Architecture and Serverless Opportunities, as this architecture pattern is a way to process data asynchronously.

Table of Contents

Executing Tasks: Sync versus Async

Two types of programming models that typically make up an app are: synchronous and asynchronous.

Synchronous execution means the first task in a program must finish processing before moving on to executing the next task whereas asynchronous execution means a second task can begin executing in parallel, without waiting for an earlier task to finish.

Sync vs async schema


Real-World Examples

For those looking for another way to understand their differences or find a creative way to explain them to a pal, here are two real-world analogies.

Synchronous: You want a burger and decide to go to McDonald's. After you order the burger at the counter, you are told to wait as your burger is prepared. In this synchronous situation, you are stuck at the counter until you are served your burger.

Asynchronous: You want a burger and decide to go to Five Guys. You go to the counter and order a burger. Five Guys gives you a buzzer that will notify you once your burger is ready. In this asynchronous situation, you have more freedom while you wait.

Disclaimer: just to make sure we're aligned, we're not judging the performances of McDonald's and Five Guys here, this is purely fictional.

One type of programming is not inherently better than the other. They are just different, each with their own unique advantages, and are used in different scenarios. Depending on what you're building, you can and probably will use both sync and async tasks.

Technical Examples

We have selected 4 common examples of when synchronous and asynchronous processing are used in applications.

Synchronous Processing

  • User Interfaces: User interface (UI) designs are typically synchronous. Since UIs are spaces where humans and computers interact, it is ideal for them to replicate the communication standards and practices humans are familiar with. Humans expect an immediate response when they interact with a computer!
  • HTTP APIs: HTTP APIs pass requests and responses in a synchronous fashion. Client programs sending HTTP requests usually expect a fast answer from the web server.

Asynchronous Processing

  • Batch-processing: is a data-processing method to handle large amounts of data asynchronously. With asynchronous batch-processing, large batches of data are processed at scheduled times to avoid blocking computing resources.

  • Long-running tasks: such as fulfilling an order placed on an e-commerce site are best handled asynchronously. There is no need to block resources while this task is executed.

Async Processing in Event-Based Architectures

Event-driven architecture is a model for distributed and asynchronous execution. As we discussed in Understanding Event-Driven Architecture and Serverless Opportunities, this architecture pattern consists of highly-decoupled event processing components.

Since asynchronous programming does not block the execution of other tasks or programs, multiple events can run concurrently. This provides a great experience for your users all while keeping your business organized and running efficiently.

Koyeb Supports Asynchronous Processing and the Serverless Future

Koyeb is a developer-friendly serverless platform to deploy apps globally. Thanks to native support of popular languages and built-in Docker container deployment, you can use Koyeb's serverless platform to deploy your:

  • Web apps,
  • APIs,
  • Event-driven functions,
  • Background workers,
  • Web services,
  • Cron jobs.

Since Koyeb is a unified platform that lets you combine languages, frameworks, and technologies you love, you can easily scale and run low-latency, responsive, web services and event-driven serverless functions.

See the benefits of going serverless, get started with a free account today!

Here are some useful resources to get you started:

  • Koyeb Documentation: Learn everything you need to know about using Koyeb.
  • Koyeb Tutorials: Discover guides and tutorials on common Koyeb use cases and get inspired to create your own!
  • Koyeb Community Slack Channel: Join the community chat to stay in the loop about our latest feature announcements, exchange ideas with other developers, and ask our engineering teams whatever questions you may have about going serverless.