Two Phase Commit in Distributed Transactions:
Unlike a transaction on a local database, a distributed transaction involves altering data on multiple databases. The database ensures the integrity of data in a distributed transaction using the two-phase commit mechanism. There are three phases in a two phase commit transaction and a commit point site involved. The job of the commit point site is to initiate a commit or roll back operation as instructed by the global coordinator.
- Prepare Phase: The initiating node, called the global coordinator, asks participating nodes other than the commit point site to promise to commit or roll back the transaction. If any node cannot prepare, the transaction is rolled back.
- Commit Phase: If all participants respond to the coordinator that they are prepared, then the coordinator asks the commit point site to commit. After it commits, the coordinator asks all other nodes to commit the transaction.
- Forget Phase: If all participants respond to the coordinator that they are prepared, then the coordinator asks the commit point site to commit. After it commits, the coordinator asks all other nodes to commit the transaction.
Spring Advantages with testing and Mocking
An application geared towards dependency injection is typically more testable because resources are easily replaced with test-oriented resources. Consider a service object that uses a data access object; in production, you’d inject a DAO that talked to a backend data store. But for each test you could create a DAO that returned specific, known data; this allows you to focus on the object being tested.
SOAP Vs. REST
- Soap has overhead such as body, envelope and payload. Rest just has the payload.
- Using Soap allows you to use web services standards around transaction management and security out of the box. For example, you can use username/password in the soap header. In Rest, we have to come up with the implementation of non-functional requirements such as transaction management, security.
- SOAP supports XML by default and REST comes with XML and JSON by default.