DEV Community

Cover image for Synchronous and Asynchronous Programming
Hazar nenni
Hazar nenni

Posted on

Synchronous and Asynchronous Programming

Synchronicity refers to the way our code is executed. We usually have two programming models Synchronous and Asynchronous ( aka sync & async ).
Those models are used to build APIs , event-based architectures and helps to decide how to handle long-running tasks.
πŸ“Œβ€‹ It's important to choose when and which method to use.
In this blog, we'll discover when we should apply async programming and when using the sync method is the best option.

let’s start by identifying the difference between asynchronous and synchronous programming.

  • In Synchronous programming, code is executed sequentially. This means that tasks are processing one at a time, if one task is not completed the other once are blocked.

sync prg

  • However, Asynchronous programming guarantee that all tasks will be carried out in parallel. Which means that your code will continue to be executed no matter the status of the previous tasks.

async prg

When to use sync programming:
When it comes to sync programming it's relatively complex. It may over-complicate things and makes it hard to deal with code.
On the other hand, it's fairly clear method, its code is easier to write and doesn’t require tracking and measuring process flows (as async does). It could be appropriate for a shopping app, for example.

When to use async programming:
Async programming is ideal when we aim to create projects with a huge number of iterations. Thus, steps doesn't require to have fixed sequences, it assures that the process of developing is growing simultaneously.

Conclusion
When it comes to choosing async or sync methods, none of them is inherently better. You just need to pick the most optimal solution for your project requirements.

πŸ‘©β€πŸ’»β€‹πŸ§‘β€πŸ’»β€‹πŸ§ β€‹ ..

Top comments (2)

Collapse
 
imedelmottakel profile image
Imed Elmottakel

Thanks, that's very interesting !

Collapse
 
hazarnenni profile image
Hazar nenni

Appreciated :)