Two-Phase Commit (2PC) is a standardized protocol that coordinates all the processes that participate in a distributed atomic transaction on whether to commit or abort (rollback) the transaction. It ensures that either all databases are updated or none are, providing strong consistency.
Transferring funds between two different bank databases (Shards). Both shards must confirm they are ready to commit before the transaction is finalized.
# Code Concept for Two-Phase Commit (2PC)\n# This pattern is architectural.\n\nclass Service:\n def execute(self):\n # Implementation logic\n pass