Exploring Apache Ignite With Spring Boot

For the use cases that I am going to describe here, I have 2 services:

  1. courses-service basically provides CRUD operations for dealing with courses and instructors.
  2. reviews-service is another CRUD operations provider for dealing with reviews for courses that are totally agnostic of courses from courses-service.

Both apps are written in Kotlin using Spring Boot and other libraries. Having these 2 services, we are going to discuss distributed caching with Apache Ignite and Spring Boot, and we’ll see how we can use code-deployment to invoke remote code execution via Apache Ignite on a service.

The Power of ShardingSphere With Spring Boot

I have developed a small-scale application that concentrates on a straightforward business scenario of customer reviews for the purpose of illustrating various use cases. This application is implemented using the Spring Boot framework and communicates with a MySQL database via Spring Data JPA, with the code being written in Kotlin. It exposes a simple REST API featuring CRUD operations on reviews.

Spoiler alert: The use cases illustrated in this article are intentionally simplistic, intended solely to showcase the integration with ShardingSphere functionalities; the discussed problems here can be solved in various ways and maybe even in better ways, so don't spend too much on thinking "why." So, without further ado, let's dive into code.

Exploring Hazelcast With Spring Boot

For the use cases I am going to describe here, I have two services: courses-service and reviews-service:

  1. Courses-service provides CRUD operations for dealing with courses and instructors.
  2. Reviews-service is another CRUD operations provider for dealing with reviews for courses that are completely agnostic of courses from courses-service

Both apps are written in Kotlin using Spring Boot and other libraries. Having these two services, we are going to discuss distributed caching with Hazelcast and Spring Boot and see how we can use user code-deployment to invoke some code execution via Hazelcast on a service. 

Projections/DTOs in Spring Data R2DBC

When dealing with Spring Data JPA or Spring Data R2DBC, we all know that everything revolves around entities. You usually create a repository, and in most cases, it either extends the JpaRepository<T, ID>  for Spring Data JPA or the R2dbcRepository<T, ID> for Spring Data R2DBC, and then you’re ready to talk to the database. With the repository in place, things are pretty straightforward: you either use the standard already-provided interface methods, you write derived-query methods, or you can use the @Query annotation to write custom stuff. Up until here, everything’s nice. As I said, everything revolves around entities (with minor exceptions, you can get a primitive return type with a custom query like an Int or String), so as a response, you’ll always get an Entity/List<Entity> for JPA and Mono<Entity>/Flux<Entity> for R2DBC. However, there are certain scenarios when you either don’t want to fetch the entire entity because some columns are redundant/not-needed or, even more, you need to construct a POJO from something completely different from your entity, yet still somehow related. Think about a group by, some counts, or some mapping at the database level, and by default you can’t do that – your repos are bound to entities.

That is when projections and DTOs come into play. For Spring Data JPA there is already a fair amount of documentation/info around (official documentation, Vlad Mihalcea, Thorben Janssen, and so on). This is not the case when it comes to Spring Data R2DBC (we still have amazing documentation here).

Testcontainers With Kotlin and Spring Data R2DBC

In this article, we will discuss testcontainers library and how to use it to simplify our life when it comes to integration testing our code.

For the purpose of this example, I am going to use a simple application with its business centered around reviews for some courses. Basically, the app is a service that exposes some GraphQL endpoints for review creation, querying, and deletion from a PostgreSQL database via Spring Data R2DBC. The app is written in Kotlin using Spring Boot 2.7.3. 

Kafka JDBC Source Connector for Large Data

Recently I had a task to migrate some data from an old monolith’s Oracle database to a microservice with a PostgreSQL database. The problem was that the data needed for migration had a parent table with around 2 million records with 150 columns and on top of that, everything was brought into view with a payload column aggregating data from various tables in XML. As you can imagine, the SELECT from that view was pretty slow, and by pretty, I mean insanely slow which was not going to work very well for the connector. So, in this article we’ll take a look at a similar simplified use case and how can we deal with it.

Use case

We have a course-catalogue application with a PostgreSQL database that deals with instructors and their courses. Now we need to migrate some legacy instructors from another PostgreSQL database that soon is going to be decommissioned. So we have instructors-legacy-db and the course-catalog-db. In our case, both databases won’t be that overwhelmed with records, with just about 200 records for the instructors-legacy-db, but for the sake of the example, just imagine that instructors-legacy-db is that table with 2 million cumbersome records. 

Error Handling in Spring for GraphQL

The Problem

Recently, I wrote some GraphQL endpoints and got a bit blocked when I came to the error handling mechanism. Usually, when writing REST endpoints, you either go for a particular @ExceptionHandler for your controller or you go for the @ControllerAdvice to handle exceptions globally for multiple controllers. Apparently, that is not the case for GraphQL. There is a completely different approach for handling errors.

First, the most important thing that I should mention is that I am using:

Refactor Switch to a One-Liner

Intro

In this article, we’ll take a look at why switch is almost never a good idea in OOP. We are going to look from different perspectives at how it affects the code, tests, and maintainability. Afterwards, we’ll do some refactoring on our existing code and analyse the benefits of the newly refactored code. We’ll see how almost any (no matter how long) switch can and should be converted to an elegant one-liner. All the source code used in this article can be found here, which has two branches — the un-refactored code (main) and the result after refactoring (feature/refactor-switch).

switch Is Almost Never a Good Idea

How many times have you come across some code that you need to add some changes to or modify something, and you do this?

Overcoming Some Pitfalls of the Google Maps API

Intro

Recently I had to integrate with Google Maps API for a job-related task. I had a great experience working with Google Maps API both on the backend and frontend, but it was not without problems and a lot of research. In fact, I did learn a lot and for this very reason, I decided to share some of the most interesting pitfalls that I fell in.

To show you what I learned I assembled a small no-brainer application. It is a Spring Boot/Thymeleaf web application with the mission to display on a map the employees from an organization. It can display a particular employee on the map, all the employees on the map, and during the creation of an employee, it allows picking an address from a pinpoint on a map. The features that I decided to implement are for the sake of tutorial purposes and they may not make a lot of sense sometimes. The app can be found here: employee-locator

Sprinkle Some ELK on Your Spring Boot Logs

 

One day, I heard about the ELK stack and about its advantages, so I decided to get my hands on it. Unfortunately, I struggled to find solid documentation and supplemental content on getting started. So, I decided to write my own.

REST + MongoDB + HATEOAS?

REST?

Recently I had an interesting experience while implementing HATEOAS to a REST web service, and I was also lucky enough to get to try out a NoSQL database named MongoDB, which I found really convenient for a lot of different cases where you don't need to manage transactions. So, today, I'm going to share with you this experience. Maybe some of you are going to learn something new maybe not, but still, you'll get a refresher on what you already know.

So, first of all, we're going to introduce REST, and slowly we'll get to HATEOAS and MongoDB. So, what is exactly REST?