2
I am working on an application that is divided into two modules, each one in a language (.NET and Java).
Application A (.NET) will manipulate the records of a table while application B (Java) will manipulate it at the same time.
Scenario: Imagine that I have a Client and Balance structure in the account.
When the customer does not exist, both applications can register it. In order for the client not to be duplicated in the database, a Unique was created in the database (Oracle).
So far so good, there will be no client twice. The problem begins when both applications are making the moves in the customer account.
Example: Imagine that the application . Net makes a deposit of R $ 50,00. At this time the record in the table will be 50 of balance. But if at the same time this deposit, a routine was made that withdraws R $ 10,00 of this client’s balance.
I would need to control the transaction between two applications, IE, if a deposit of R $ 50,00 and a withdrawal of R $ 10,00 at the same time (hypothetically speaking), the final balance of the customer should be R $ 40,00.
The scenario that I have today, the applications recover the customer’s record, perform the calculation and return to the table the updated value, but there is an overlap of the data. For example, the transaction . NET launches balance of R $ 50,00 and the Java application launches withdrawal of R $ 10,00 at the same time. As for the application . NET recovers the client’s centralized record, it has 0 balance, as does the Java application. If the application . NET finish first, it launches 50 of balance and then the Java application launches 10 of withdrawal, getting the record in the table of -10.
Is there any way to control this between the two applications only with transaction each application with yours? I’ve been thinking and imagined a scenario where there should be a service using LOCK to treat this type of operation. Imagine another way to solve?
Note: it is a legacy system, change the way of storage of the balance would be virtually unviable.
Thanks!
opa Victor, thank you for the reply.
– Leo Limas
Is this the only option? Can’t bank-separated applications do something? Transaction type, etc
– Leo Limas
@Yes, there must be a lot more possible solutions. But once you put the [oracle] and [transactions] tags yourself into the question, I imagine a response of the kind "Just use oracle transactions." is not what you expect in response.
– Victor Stafusa