0

We are about to build a SaaS application. Now we are in the phase of deciding the technology stack. We have developed earlier applications with spring boot and hibernate. So our team currently thinking to use the same stack for the new product.

But here are our concerns.

  1. The applications we built earlier were all client based applications with not so heavy traffic. But the application we are planning to build is a cloud based product. The expected traffic will be very high.

  2. It will be a multi tenancy application. Based on the growth we may need to expand the resources horizontally. As we are planning to use cloud infra we should have the control to optimize the queries to the deep extend.

  3. We should have option to implement second level cache in deep.

  4. We can't let the framework fire queries on its own. We should have complete control on it. (Ex. Child objects will gets loaded automatically while accessing it in hibernate)

With all these points in mind, will Hibernate serve the purpose? Or later once the product grows will it be very challenge to enhance or customize? Or is there any other frameworks there for high traffic scaling? Or can we proceed writing the entire layer on our own?

Any suggestions?

Rajeshkumar
  • 815
  • 12
  • 35

1 Answers1

0

Sure, Hibernate can be used for such scenarios. If you want to be in control of the queries, you should be using a DTO approach though to avoid lazy loading.

Coupled with a query builder like Blaze-Persistence provides, you can also make use of the more advanced features of your database. You could then use Blaze-Persistence Entity Views for DTOs, which is a library I created to allow easy mapping between JPA models and custom interface or abstract class defined models, something like Spring Data Projections on steroids. The idea is that you define your target structure(domain model) the way you like and map attributes(getters) via JPQL expressions to the entity model.

A sample DTO model could look like the following with Blaze-Persistence Entity-Views:

@EntityView(User.class)
public interface UserDto {
    @IdMapping
    Long getId();
    String getName();
    Set<RoleDto> getRoles();

    @EntityView(Role.class)
    interface RoleDto {
        @IdMapping
        Long getId();
        String getName();
    }
}

Querying is a matter of applying the entity view to a query, the simplest being just a query by id.

UserDto a = entityViewManager.find(entityManager, UserDto.class, id);

The Spring Data integration allows you to use it almost like Spring Data Projections: https://persistence.blazebit.com/documentation/entity-view/manual/en_US/index.html#spring-data-features

Page<UserDto> findAll(Pageable pageable);

The best part is, it will only fetch the state that is actually necessary!

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58