Performance of ULID and UUID in Postgres Database

Hello everyone! In this article, I want to share my knowledge and opinion about the data types that are often used as an identifier. Today we will touch on two topics at once. These are measurements of search speed by key and data types for the key on the database side.

I will use a PostgreSQL database and a demo Java service to compare query speeds. 

Can Redis Be Used as a Relational Database?

Let's start with the question, "How do you use Redis?" I'm sure most use it as a cache for the service. I hope you know that it can do more than just that. Recently, I spoke at a conference with a report on how we moved part of the data to Redis and requests fly to it in the first place. Now I want to tell you not about how we applied it, but about the fact that when working with Spring and its abstractions, you may not immediately notice the substitution.

Let's try to write a small Spring app that will use two PostgreSQL and Redis databases. I want to note that we will store in the databases not some kind of flat object, but a full-fledged object from a relational database with nested fields (inner join). To do this, we need plugins that need to be installed in Redis such as RedisJSON and RediSearch. The first allows us to store our object in JSON format, and the second allows us to search by any field of our object, even nested fields.

Proper Java Exception Handling

Let's talk about sore points. Due to my duties, I have to work with many different services (make edits, conduct code reviews ...); different teams usually write all these services, and whenever it comes to handling errors and forwarding them from the service, sometimes my eyes start watering. Let me try to tell you what code, in my opinion, is not acceptable for error handling and how it should be in my opinion.

In general, initially, the problem is hidden in the flaw in the analytics of the service. Often, there is no requirement in terms of reference on how errors should be thrown. As a rule, this happens for two reasons; the first is the rush to develop a new service, and the second is that the analyst trusts the experience of the developer. In such cases, the analyst simply tells the developer, "Well, give me an example of an error message later, and I will attach it in confluence."

Architectural Miscalculation and Hibernate Problem “Type UUID but Expression Is of Type Bytea”

Nowadays, it is difficult to find a service that works on its own and does not communicate with other services, especially modern systems that are built on a microservice architecture. In this regard, there are difficulties in obtaining data from one or another service since not all the data necessary for the operation of the service is stored in one database, and you cannot simply make a "join." I want to talk about one of these problems and its solution in this article.

Case Description

A huge number of projects use Spring + Hibernate. This bundle gives an advantage in development speed, reducing the amount of code and blah blah blah. But there are also disadvantages.