How do you manage complexity in code and architecture?

Posted by dondraper36@reddit | ExperiencedDevs | View on Reddit | 12 comments

That’s something I reflect on almost every day when I discuss code design and architecture with my colleagues, or when working on a feature.

My main reasoning in that aspect is that we should always divide the total complexity into the 2 well-known categories: essential, inevitable and dictated by the task itself, and also accidental, which is the complexity we introduce with our choices.

This separation is helpful in that you can understand the minimum level of complexity. For example, if you need to persist your user data, that is calling for a database. Then come our database choice.

In general, I always try to follow the “use the simplest approach that works“, as described by Sean Goedecke here.

https://www.seangoedecke.com/the-simplest-thing-that-could-possibly-work/

The problem is that the word “simple” can have as many interpretations as there are devs on your team.

The example from Sean above is about Redis. On the one hand, it’s a popular and battle-tested piece of technology designed for cases when you need, say, caching or distributed rate-limiting.

On the other, and that’s my subjective opinion, introducing a new technology, however good it is, is always adding complexity.

That is why I usually do my best to keep using just Postgres as long as possible for queuing (for update skip locked), caching (unlogged tables help here), and unstructured data (jsonb).

I have had many arguments with people whose main objection was that you need to use the right tool for the job and how this approach might break when we have 100x load.

While it might be true, I am pretty cynical in that most projects are not even likely to reach that stage. If they do, however, it is most likely quite a successful milestone when you can afford to rewrite certain parts of your architecture and adapt to the new load.

Sometimes, I have no quantifiable criteria to select one approach over another. Even worse, I am not even sure I can sort them by “complexity”, which becomes apparent when my colleagues the alternative approach simpler.

Maybe, you have developed your own vision of simplicity and complexity and how you make such decisions. All that would be extremely interesting to hear