Modern C++ continuous integration build pipelines might produce huge logs which may be easily overlooked. Among other errors/warnings, a potential risk caused by invalid narrowing assignments might be lurking in those dark corners... This write up is a little reminder about an essential feature in modern C++ compilers and can help defend against that specific problem. Prior to C++11, the following was a valid assignment and still is even in C++20 or higher ... unsigned int unsignedSinceBirth = 10; unsignedSinceBirth = -10; // assigning a negative value to an unsigned container printUnsignedVal(unsignedSinceBirth); which when compiled using these options "g++ -std=c++20 <cpp files> -o <executable-name>" does not even emit a warning. And an executable is generated successfully. The output of running that code is an arbitrary unexpected value. Modern C++ (post Cpp11) allow uniform initialization syntax which can help the compiler detect this situation as follows:
A seminal question to answer in a distributed event driven "fault tolerant" system is how to recreate state should there be a need for fault tolerance and recovery. A typical and easy to rationalize approach is the assignment of a globally increasing sequence to the events flowing across the system. The intent is to bring a global "order" or "sequence" into the system. Later on this global ordering will pave the way for a resilient yet distributed system. It will be: predicable - replaying the events from message commit logs will always produce the same net effect. reliable and fault tolerant - as long as there are commit logs maintained, faults recovery and late joining protocols will always have a way to catch up. The question then turns to " who should assign the order or sequence "? This post attempts to answer the 2nd question in an expository style (and will not delve into details). .......................................................