0

I am creating a service using Lagom framework and need some help in the architecture of the application. There is Employee service which contains information about all the employees. Each employee has an address. The models are like these,

class Employee {
      String firstName;
      String lastName;
      String email;
      Address address;
}

class Address {
    String apt;
    String street;
    String city;
    String state;
    String pin;
}

Right now I am creating a single service for employee and thinking of using Cassandra for the database. Should I create a single table for employee which contains a custom user type (UDT) of address or create a separate service for address and use this service in the employee service. Also can someone point me to a Lagom framework example which demonstrates the use of UDT in Cassandra.

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
konghoho
  • 53
  • 6

1 Answers1

0

The recommended way of persisting data in Lagom is to use event sourcing, described here:

https://www.lagomframework.com/documentation/1.3.x/java/PersistentEntity.html

So you don't store your state directly in tables, you store the events that led to that state. For example, you might have an EmployeeAdded event, and an EmployeeAddressChanged event, and so on, depending on what make sense to model in your business use case. These are the things that get persisted, and then when the employee is loaded, Lagom will replay all the persisted events to create the Employee type that you have above.

James Roper
  • 12,695
  • 46
  • 45
  • Thanks for the response and it makes much more sense. I read through whole "Writing persistent and clustered services" section of the docs. Just need one clarification, in Cassandra read-side, I have to create a custom user type(UDT) of address and an employee table and in the event handler registered with the read side processor, I have to update the employee table. Is there a way to create a custom user defined type (UDT) in Lagom rather than manually creating in Cassandra. I know I can create table with CassandraSession-executeCreateTable. – konghoho Oct 03 '17 at 03:20
  • Not sure why you'd need to create a user defined type - personally I wouldn't do that, I'd just store my data across multiple columns. But, if you really want to do that, executeCreateTable is actually very poorly named, it can be used for any DDL statements including UDTs, so just use executeCreateTable. See https://github.com/lagom/lagom/issues/647 for more details. – James Roper Oct 03 '17 at 04:32