The Private Method Paradox: When Encapsulation Clashes with Testability

As backend programmers, especially those of us deep in Java and Go, we often grapple with fundamental design principles. One that frequently sparks debate is the use of private methods for encapsulation. We’re taught it’s good practice, shielding internal logic from the outside world. But what happens when that shield makes our code a nightmare to test? And worse, are we creating “bad” unit tests by peeking behind the curtain?

Continue reading “The Private Method Paradox: When Encapsulation Clashes with Testability”

Robust Error Handling with Quarkus REST Client and SmallRye Fault Tolerance: A Deep Dive

In modern microservices architectures, applications frequently interact with external services. Ensuring resilience and graceful degradation in the face of failures is paramount. Quarkus, with its lightweight nature and developer-friendly features, coupled with SmallRye Fault Tolerance, provides powerful tools to achieve this.

Continue reading “Robust Error Handling with Quarkus REST Client and SmallRye Fault Tolerance: A Deep Dive”

Building a Robust API Gateway with Quarkus and Clean Architecture


Level Up Your API Gateway: Quarkus + Clean Architecture

So, you’re building an API Gateway? Excellent choice! And if you’re considering Quarkus for the job, you’re already on the path to a high-performance, cloud-native solution. But to truly make your API Gateway shine – to ensure it’s not just fast, but also robust, maintainable, and adaptable to future changes – let’s talk about incorporating solid architectural principles like Clean Architecture or Hexagonal Design.

Continue reading “Building a Robust API Gateway with Quarkus and Clean Architecture”

IO Threads vs. Worker Threads in Quarkus: A Guide to Optimal Performance

Quarkus, the Supersonic Subatomic Java framework, thrives on its reactive architecture. A core component of this architecture is the efficient management of threads, specifically IO threads and worker threads. Understanding the differences and proper usage of these thread types is crucial for building high-performance, responsive applications.

Continue reading “IO Threads vs. Worker Threads in Quarkus: A Guide to Optimal Performance”

Quarkus Configuration: Leveraging Environment Variables

Quarkus, known for its supersonic subatomic Java, provides a flexible configuration system that allows you to manage application settings from various sources. One powerful and often overlooked method is using environment variables. Let’s dive into how you can harness the power of environment variables to configure your Quarkus applications.

Continue reading “Quarkus Configuration: Leveraging Environment Variables”

UUIDs vs. ULIDs in Hibernate: Choosing the Right ID Generator

When working with Java Hibernate, one of the crucial decisions you’ll make is how to generate primary keys for your entities. Traditionally, auto-incrementing integers have been the go-to choice. However, in modern distributed systems, UUIDs and ULIDs are gaining popularity. Let’s delve into the pros and cons of each, specifically within the context of Hibernate.

Continue reading “UUIDs vs. ULIDs in Hibernate: Choosing the Right ID Generator”

Taming the Lazy Beast: Reactive DTOs and Hibernate Relationships in Quarkus

Building reactive applications with Quarkus and Hibernate Reactive is a fantastic way to achieve high performance and responsiveness. However, you’ll inevitably encounter the “lazy loading” challenge when dealing with entity relationships and Data Transfer Objects (DTOs). This post will guide you through the common pitfalls and provide practical solutions to ensure smooth data flow in your reactive Quarkus applications.

Continue reading “Taming the Lazy Beast: Reactive DTOs and Hibernate Relationships in Quarkus”

FindTheClosest

public class FindTheClosest {

    private final Number target;
    private final Number[] numbers;

    public FindTheClosest(Number target, Number[] numbers) {
        this.target = target;
        this.numbers = numbers;
    }

    public Number execute() {
        Stream<Number> stream = Arrays.stream(numbers);
        Optional<Number> optional = stream.min(Comparator.comparing(number -> {
            double delta = target.doubleValue() - number.doubleValue();
            return delta == 0 ? Integer.MAX_VALUE : Math.abs(delta + 1F / Integer.MAX_VALUE);
        }));
        return optional.orElse(target);
    }
}

iluwatar/java-design-patterns: Design patterns implemented in Java

Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system. Design patterns can speed up the development process by providing tested, proven development paradigms. Reusing design patterns helps to prevent subtle issues that can cause major problems, and it also improves code readability for coders and architects who are familiar with the patterns.

Source: iluwatar/java-design-patterns: Design patterns implemented in Java