/images/anrosca.png

Introduction to DynamoDB and single table design

Introduction In this post, we’ll try to familiarize ourselves with Amazon’s DynamoDB database and the famous single table design. Coming from the relational world, DynamoDB looks like a strange beast at first (it’s a NoSQL database after all) and definitely has a steep learning curve, hopefully this introduction will make things easier. We’ll try to write a simple Spring Boot rest api which uses DynamoDB under the hood, so that we’ll get a chance to see how everything looks in practice.

Exposing Kafka producer & consumer metrics to actuator

Introduction In this blog post we’re going to explore how to expose Apache kafka's producer and consumer metrics to Spring Boots's actuator, and then importing them into prometheus and displaying them as a Grafana dashboard. Doing this will help us keep track of kafka’s producer and consumer performance and also will help us to see the impact of specific producer or consumer configuration properties. Creating a simple Kafka producer application with spring boot Let’s go to https://start.

Creating a custom Spring Boot test slice

Introduction In Spring Boot, when writing tests there’s a way to slice up the test’s application context, so that it contains only the beans which are appropriate for the given test. Some examples are @WebMvcTest, @DataJpaTest, @RestClientTest and many others. For example, when testing a jpa repository, we’re not interested in the web-related components (like controllers), so using the @DataJpaTest will reduce the size of the application context, so that it contains only the repositories and other infrastructure related to that (like DataSources, EntityManagerFactory and others).

Bootiful error handling with @ControllerAdvices

Introduction Today we’re going to look at how to return pretty error responses for our REST APIs, using Spring Boot's controller advices. Even though controller advices are a well-known mechanism, no many projects use them to their full potential. In this article we’ll try to fix that. The REST api Initially, we’ll need a couple of HTTP endpoints, so that we can simulate some errors and see if we as users of that REST api can understand what went wrong.

Introduction to Spring Framework 6 HTTP interfaces

Introduction The Spring Framework version 6, along with (Spring Boot version 3) will introduce the ability to consume HTTP apis in a declarative way using interfaces. This feature resembles the Spring Data way of writing repositories, where we just create an interface and declare what methods it should have and Spring Data will create a proxy, implementing all SQL queries. It’s worth pointing out that Spring Framework 6 is still in the snapshot state and the current article reflects the state of the things as they are in June 2022.

Optimistic and pessimistic concurrency control with Spring-Data-JPA

Introduction Today we are going to learn about the difference between optimistic and pessimistic concurrency control using Spring-Data-Jpa. Concurrency control is about managing concurrent access to our data. Let’s say for example that we have a hotel booking system and there’s only one room available in the hotel and 2 users at the same time try to book it. Who will get the room? Well, it’s possible that both of them will succeed, but that will leave the hotel staff with an awkward situation.

Spring puzzler: the @TransactionalEventListener

Introduction Today we’re going to take a look at a new Spring @Transactional puzzler involving the @TransactionalEventListener. It’s an old quirk of Spring related to transaction-bound events (both declarative and programmatic ones) and though not commonly experienced, encountering it can leave you confused for hours. Let’s have a look. The puzzler Suppose we have the following code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 @Slf4j @SpringBootApplication public class SpringDeclarativeTxManagementApplication { public static void main(String[] args) { SpringApplication.

Spring puzzler: transactional @PostConstruct methods

Introduction Today we’ll be looking at a Spring puzzler - transactional @PostContruct methods. Though it’s not a commonly used thing, it can be useful to know some limitations of the Spring’s declarative transaction management approach. @PostConstruct methods The @PostConstruct are called automatically by Spring after all of the bean’s dependencies were injected. Let’s look at an example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 @Slf4j @SpringBootApplication public class SpringDeclarativeTxManagementApplication { public static void main(String[] args) { SpringApplication.

Introduction to declarative transaction management in Spring Framework

Introduction In this blog post we are going to explore the internals of Spring’s declarative transaction management. We’ll start with the basics, and then we’ll dive deeper, looking at the internals and some potential pitfalls which we can run into. We’ll be using: Spring Boot 2.6.7 Java 17 Postgresql Spring Data JPA But first, let’s discuss a bit why do we even bother with transactions in the first place?