Building Better Teams

Articles and Posts

Blog

 

Editing Shared Resources

Imagine you want to store a simple key:value pair in redis, like a session object. What if you have many active requests that all want to make changes at the same time? How do we deal with that?

In this series of articles we will explore the major compromises, solutions, and trade-offs you will find when trying to pick a solution. We’ll start with the easiest concepts first and move into the more complicated ones. We’ll look at the real solutions and issues that are common to most web frameworks and look at alternative solutions too.

Please note that while the focus is on the example of a session object, there isn’t much that makes this specific to sessions, you can generalize the concept to databases, files, or any sort of resource you like. A Session is just our example for this series because it’s something quick to understand by a lot of web developers.

General Advice

  • Shared state is easy to overlook.

  • Resource locking requires slowness

    • Locks can be hidden in places you don’t expect, especially in big frameworks, or even the low-level libraries that connect systems.

    • Reduce locks to the smallest amount of logic as possible, try to do all your writes at once.

  • Query optimization

    • Look at the execution plans

  • Don’t put anything into the session (except the authentication part).

Brian Graham