Common Practices for Middleware
In this section, we’ll review a number of common practices when writing your own middleware to keep everything running optimally in your web application. Let’s get started!
Defer to Asynchronous
When working with Middleware, we want to get the best performance possible so our users can begin working in the application. As more users continue to use the application, performance may suffer.
A synchronous operation is where code is executed and the application has to wait for it to finish, meaning it’s single-threaded and runs on the application’s main thread, but when an asynchronous operation is executed, it creates a new thread and lets the framework know what to call when it’s finished processing. This is signified through the async
/await
keywords.
For the majority of Middleware operations, it’s best to use asynchronous calls when applicable. This will increase Middleware (and application) performance...