My Logging Best Practices If you are a backend developer like me, logging is the window to your application. Unlike in the frontend, there’s not much to see except from some logging messages. Here are some of my personal guidelines I use when I write logs. Log after, not before Back in the days, a logbook was written on […]
Idempotent events with revision numbers In an event-based system (possibly according to DDD) you will be notified about changes. For example, if the price of a product has changed, a PriceUpdatedEvent will be thrown. Any system interested in price updates can listen and react to those events. In most cases the reaction triggered by an event should be idempotent. This […]
Concrete vs Generic – The story of a data model The story of a project In the last project I was working on, we struggled a lot with our data model. The task was to replace an old product service with a new one. The old system has grown over time, was hard to maintain and the guys who made it have been gone a […]
Don’t depend on details – an example I recently read Clean Architecture by Robert C. Martin. The book gives a simple advice: don’t depend on details! For Uncle Bob details are things like the database or message broker. Your architecture shouldn’t depend on the actual used implementation of those details. Whether your are using Oracle, MySQL or DynamoDB, whether it’s ActiveMQ, Kinesis […]
find vs. get Three years ago I wrote a blog post with the provoking title “Don’t use Optionals for data repositories“. The post received a couple of critical comments and I had the feeling that I didn’t made my point clear. This week I stumbled over the same topic again, but from a slightly different point of view. […]
Encapsulated modules and clean tests with Spring’s @Configuration Usually we use Spring’s @Configuration to define some special beans. A classic example is the definition of a data source: 1234567 @Beanpublic DataSource dataSource() { DataSource dataSource = new DataSource(); dataSource.setUsername(username); // ... and so on ... return dataSource;} However, we can also use Spring’s @Configuration to build better modules which helps us to writer cleaner tests. Let’s go through an example. An example Let’s assume we have an application which uses domain […]
Messages vs. Events vs. Commands In a distributed environment, services must communicate with each other. One of the most popular ways of communication is messaging. Tools like ActiveMQ, RabbitMQ or Kafka are making it easy to exchange messages between systems. But no matter which broker you are using, you must decide which kind of message you want to send. Messages […]
Queues vs. Topics vs. Virtual Topics (in ActiveMQ) ActiveMQ provides a variety of different messaging patterns. While queues and topics are the most famous ones, virtual topics can combine the best of both worlds: multiple consumers with their own dedicated queue. Queues Queues are the most obvious messaging pattern implemented by ActiveMQ. They provide a direct channel between a producer and a consumer. […]
Programming to an interface Program to an interface, not an implementation. This short sentence, introduced in 1994 by the GoF, is one of the most important design principles in software development. However, I have seen several projects where this principle has gone wrong. Here’s why: Interface vs. Interface If you come from a Java background like myself and you […]