0

I have created a SpringBoot app that connects to two databases (using separate JPA config) for data read and write operations. Data is manipulated and partially persisted in two databases (DB servers are in two separate infrastructures). Similarly, the data from these separate DBs are combined and served back to the client during the read operations. Both read and write operations for a single record took more than 3 sec each (I think it's obvious as the DBs are in separate infra).

I need to improve the performance of both read and write operations. I have improved the read performance to less than a sec by introducing the Redis cache. How can I improve the performance of write operations? Please suggest possible options. Thanks in advance!

Code: [Here customerRepository refers to one DB and splitCustomerRepository refers to the other. First save the partial data in first DB and use the primary key id to create the remaining data in second DB]

public String createCustomer(CustomerRequest customerRequest) {
        String message = "";
        try {
            customerRequest = applyRules(customerRequest);
            CreditCardRequest cardRequest = customerRequest.getCreditCard();
            CreditCard card = CreditCard.builder().cardNumberPart1(cardRequest.getCardNumberPart1())
                    .cardType(cardRequest.getCardType()).cvv(cardRequest.getCvv()).expiry(cardRequest.getExpiry())
                    .pinPart1(cardRequest.getPinPart1()).build();
            Customer customer = Customer.builder().address(customerRequest.getAddress()).age(customerRequest.getAge())
                    .name(customerRequest.getName()).ssnPart1(customerRequest.getSsnPart1()).creditCard(card).build();
            for (Address address : customerRequest.getAddress()) {
                address.setCustomer(customer);
            }
            customer = customerRepository.save(customer);
            addressRepository.saveAll(customerRequest.getAddress());

            SplitCreditCard splitCreditCard = SplitCreditCard.builder().id(customer.getCreditCard().getId())
                    .cardNumberPart2(cardRequest.getCardNumberPart2()).pinPart2(cardRequest.getPinPart2()).build();
            SplitCustomer splitCustomer = SplitCustomer.builder().id(customer.getId()).creditCard(splitCreditCard)
                    .ssnPart2(customerRequest.getSsnPart2()).build();
            splitCustomerRepository.save(splitCustomer);
            message = "Customer successfully created!";
        } catch (Exception e) {
            LOGGER.error("Exception occurred while creating customer", e);
            message = "Failed to create customer, exception occurred - " + e.getMessage();
        }

        return message;
    }
Shihad Salam
  • 79
  • 2
  • 11

0 Answers0