Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
One way to go is probably to use some kind of transaction scope to include everything (SELECT from order and INSERT into shipment) with a high enough transaction isolation (e.g. SERIALIZABLE for SQ...
Answer
#1: Initial revision
One way to go is probably to use some kind of transaction scope to include everything (SELECT from order and INSERT into shipment) with a high enough transaction isolation (e.g. SERIALIZABLE for SQL Server). However, this might prove very expensive if you need a high transaction throughput. **In practice, this is not an issue**: - the likelihood of this happening is very low - even if it happens, the shipment lifecycle is long enough to allow this to be checked later. E.g. I expect the system to have multiple states for a shipment. You have just created it here in your code, but there must be some validation later on. While this might be strange for a developer, for most folks, **living in an inconsistent state for a while is perfectly natural** because most things take time to settle. Examples might include the period to get a new card, ID, or any type of license while the old one might be still in use. In your particular case having a shipment for a canceled order is not a big deal as long as this case is checked upon before actually dispatching the shipment. Of course, there are cases when this consistency must be enforced. If the likelihood of this happening is 1 in 100K and the result would be a plane crash, it cannot be allowed to happen.