Lock Your Objects!
Learn how to protect data structures for concurrency-safe access.
Regarding the fundamentals of building back-end servers, there is one essential thing we have yet to cover—concurrency-safe access.
Understanding concurrency
Here’s the thing with back-end servers—we are building one resource that multiple people will access simultaneously, unlike websites, where a bundle is downloaded and served to every browser instance of every person using it. Our server will be remotely hosted and receive requests from people worldwide. This means that we not only need to be able to handle so many parallel requests, but we also need to ensure that all concurrent requests are safe and the state is managed correctly.
What does that really mean?
Reads only
Let’s take a look at our users
slice. We have APIs to read and update the resource. If you tried the exercise in the last lesson, you might have added an API to update one specific user.
How about we simulate a few scenarios? Say we get a whole bunch of people trying to read the user info. Be it getting the entire list or just querying for one. This, in itself, should never cause concern. It’s a static list of data; what could go wrong?
Get hands-on with 1200+ tech skills courses.