Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mastering Java Persistence Best Practices for Cloud-Native Applications and Modernization

Mastering Java Persistence Best Practices for Cloud-Native Applications and Modernization

Join us for an insightful presentation as we explore the world of Java persistence in the context of cloud-native applications and modernization. Discover the fundamental principles, challenges, and strategies. From uncovering database patterns to harnessing the power of cloud-native technologies, this session will provide valuable insights for developers, engineers, and architects seeking to optimize their application's persistence layer. Take advantage of this opportunity to better understand how to create maintainable architectures, tackle data integration challenges, and embark on successful modernization journeys. Whether you're new to the concept or looking to enhance your expertise, this presentation is your guide to mastering Java persistence for the future of software development.

Otavio Santana

November 10, 2023

More Decks by Otavio Santana

Other Decks in Technology


  1. Why Do Modern Applications Need Data Storage? The new opportunities

    The current opportunity It's where the state is
  2. Development lifecycle very often starts with immature data structures Changing

    a database type in existing applications is complex and expensive. Over time, maintenance of data and schema evolution gets challenging First thing we do Persistence landscape Change Maintenance State of affairs Evolutionary Data
  3. SQL Database Database solutions Polyglot Persistence key value key key

    key value value value Wide-Column Graph Document Key Value NoSQL Database
  4. Use Case Description Caching Speeds up data retrieval by storing

    frequently accessed data in memory, reducing the need to fetch it from the backend. Session Management Stores and manages user sessions, enhancing application performance and scalability. Real-time Analytics Powers real-time dashboards and analytics by swiftly processing and aggregating data. Pub/Sub Messaging Facilitates real-time communication between components through publish-subscribe messaging patterns. Redis Use cases
  5. Simplify Schema Identify Key Patterns Use Contextual Keys Batching Operations

    Cache-friendly Design Avoid Complex Joins Beware of Over-Normalization Avoid Bloated Values Limit Indexes Redis Do and Don'ts
  6. Apollo Aphrodite Ares Kratos Duty Dead Gods Love, happy Sun

    War 13 Color Sword Row-key Columns Wide-Column Structure Duty Duty weapon
  7. Apache Cassandra User Cases Use Case Description Online Retail Managing

    e-commerce platforms, handling product catalogs, user profiles, and transaction records. Social Media Analytics Monitoring and analyzing social media interactions, tracking trends, and user engagement. Real-Time Analytics Enabling quick analysis of data streams for instant insights, critical in financial and logistics sectors. Logging and Monitoring Centralized storage and analysis of logs and monitoring data from applications and servers.
  8. Apache Cassandra Modeling tips Denormalize When Necessary Design for Query

    Patterns Choose Optimal Column Families Utilize Secondary Indexes Compression and Bloom Filters Avoid Over-Denormalization Limit Column Count Avoid Overusing Secondary Indexes
  9. 1 2 3 4 5 6 7 8 9 11

    12 10 Client R1 R2 R3 1 2 3 4 5 6 7 8 9 11 12 10 R4 R5 R6 DC1 DC2 Apache Cassandra Cluster
  10. MongoDB User Cases Use Case Description Content Management Store and

    manage diverse content types like articles, images, and videos with schema flexibility. Catalog Management Efficiently organize and categorize products or items with changing attributes and metadata. Mobile Applications Provide offline capabilities and sync data seamlessly once online, enhancing user experience. Social Media Platforms Facilitate rapid storage and retrieval of user-generated content, profiles, and social interactions.
  11. MongoDB Modeling tips Leverage Embedded Documents Design Around Use Cases

    Employ Indexes Judiciously Normalize When Logical Stay Flexible with Arrays Avoid Over-Embedding Steer Clear of Monolithic Documents Don’t Over-Index Beware of the One-Size-Fits-All Approach
  12. Neo4J Modeling tips Avoid Over-Reliance on Joins Steer Clear of

    Over-Connecting Nodes Don’t Overcomplicate Graph Design Beware of Property Index Overuse Embrace Relationship-Driven Design Craft Efficient Traversal Paths Use Labels and Types Wisely Leverage Indexing for Nodes Utilize Property Indexes
  13. Neo4J User Cases Use Case Description Social Networks Modeling user

    profiles, friendships, and interactions for effective social networking platforms. Recommendation Engines Powering personalized recommendations by analyzing connections and preferences. Knowledge Graphs Organizing and querying complex relationships in fields like healthcare, finance, and research. Fraud Detection Uncovering hidden patterns and connections indicative of fraudulent activities. Network Analysis Analyzing intricate relationships in data networks, such as transportation and communication.
  14. Mapping Mismatch 1 * Addresses Inheritance Polymorphism Encapsulation Types Normalization

    Denormalization Structure Application Database key value key key key value value value wide-Column Graph Document Key Value Challenges in a database land Different paradigms: Apps x DBMS
  15. Driver Data Mapper DAO Database integration Data Access Patterns Handling

    Data Integration in Java Active Record Repository DTO
  16. Driver Database integration Data Mapping Database Application Data Mapper Active

    Record Repository DAO Data-oriented Programing Object Oriented Programming
  17. Database-oriented Programming 4 Principles Database Data-oriented Programing 1. Separating code

    (behavior) from data. 2. Representing data with generic data structures. 3. Treating data as immutable. 4. Separating data schema from data representation.
  18. Driver Data Mapping try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS){ Statement

    stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(QUERY);) { // Extract data from result set while (rs.next()) { // Retrieve by column name System.out.print("ID: " + rs.getInt("id")); System.out.print(",name: " + rs.getInt("name")); System.out.print(",birthday: " + rs.getString("birthday")); System.out.println(",city: " + rs.getString("city")); System.out.println(",street: " + rs.getString("street")); …} } Complex relation w/ business logic Code flexibility
  19. Data Mapper Data Mapping @Entity public class Person { @Id

    @GeneratedValue(strategy = AUTO) Long id; String name; LocalDate birthday; @ManyToOne List<Address> address; … } impedance mismatch centralize mapper responsibility public class PersonRowMapper implements RowMapper<Person> { @Override public Person mapRow(ResultSet rs, int rowNum) throws SQLException { Person person = new Person(); person.setId(rs.getInt("ID")); return person; } }
  20. Data Access Object Data Mapping public interface PersonDAO { List<Person>

    getAll(); void update(Person person); void delete(Person person); void insert(Person person); } Centralize Data operations impedance mismatch
  21. Active Record Data Mapping @Entity public class Person extends PanacheEntity

    { public String name; public LocalDate birthday; public List<Address> addresses; } Person person =...; // persist it person.persist(); List<Person> people = Person.listAll(); // finding a specific person by ID person = Person.findById(personId); SOLID breaking Higher domain's responsibility
  22. Repository Data Mapping Far from database Domain oriented @Entity public

    class Person { private @Id Long id; private @Column String name; private @Column LocalDate birthday; private @ManyToOne List<Address> addresses; } public interface PersonRepository extends <Person, String> {} Person person =...; // persist it repository.save(person); List<Person> people = repository.findAll(); // finding a specific person by ID person = repository.findById(personId);
  23. Database metrics Biz. transactions Oversized / downsized Invalid/stale connections Apps

    on await state Fixed cache size No cache usage Consistency impacts w/ distributed cache Complex mapping Auto-generated schemas On-prem x Cloud Many NoSQL types SQL x NoSQL x NewSQL Eager x Lazy loading N+1 Problem Hard to change db types Persistence Config. Data storage Data Manipulation Cache Conn. Pool Framework What's next?