-4

I decided to make an application, networking application, don't know what it has to do yet but mainly it should be a cross-client kind of like framework networking application/library.

Since networking especially with sending stuff, should I use async since it's basically IO (as far as I understand, I = getting data from client and O = sending data to the client)

Also if I should use async, would there be any downsides / lag caused by using async for everything? Somebody told me once making everything async couldn't hurt but I'm not entirely sure and I want my application/library to be as stable and fast and neat as possible.

3
  • 4
    "don't know what it has to do yet" - perhaps you should think about that first Commented Feb 15, 2019 at 20:26
  • I didn't mean it like that. I know it's gonna be a networking application (most likely a server) but for what exactly I don't know, could be for a game, could be as chat server, that concerns me is the stability of the networking code for the server or client, regardless of what it's used for. Commented Feb 15, 2019 at 20:29
  • 3
    The application matters though; network communication is a big topic. There are a lot of possible scenarios which all fall under broad umbrella of networking so there's no one-size-fits-all solution. For example, different kinds of applications and even different kinds of messages within the same application lend themselves to different patterns - e.g. broadcast, direct messaging, publish/subscribe, request/response, and many more. There's also issues around the type of data being transported, the size and shape of data, whether you require any kind of persistence or durability... Commented Feb 15, 2019 at 21:01

2 Answers 2

1

Generally async, when done correctly, is much more scalable than sync. Synchronous networking code must dedicate a thread to every connection, whereas asynchronous code is free to give up its thread to another connection while it is doing nothing but waiting for the next packet to arrive.

Since that waiting happens frequently, it is a very good tradeoff to make. What you give up in exchange with async is requiring more complex, less linear code.

1

This depends. If your goal for this application is throughput above all else, then yes, using async IO is a must. However, this has far-reaching implications for the architecture of your software, because async IO implies some kind of event system. Depending on the language this may be an explicit event loop that you have to write, or may be implicit in the language. But even then, this has challenges similar to writing multithreaded code. At the very least, you will experience some difficulty with combining async and non-async code.

So async code implies substantial extra complexity. If this is your first networking application, that may be too much at once. On the other hand, certain ecosystems such as NodeJS and C# have particularly good support for async operations so that it could be more effort to avoid this.

Note also that a huge part of the internet does not use the async paradigm, for example everything built with PHP. And that's still scalable and successful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.