Tuesday, September 30, 2025

Spring Boot Actuator, Prometheus, and Grafana

 Spring Boot Actuator, Prometheus, and Grafana usually work together as a monitoring stack::


🔹 1. Spring Boot Actuator

Purpose: Adds production-ready features to a Spring Boot app.
Uses:

  • Exposes health checks (e.g., /actuator/health) → check if the app is alive.

  • Provides metrics endpoints (e.g., /actuator/metrics) → JVM memory, CPU, HTTP request counts, datasource stats, etc.

  • Allows application monitoring & management → shutdown, environment info, logging levels (if enabled).

  • Acts as the data source for Prometheus when you add the micrometer-registry-prometheus dependency (exposes /actuator/prometheus).


🔹 2. Prometheus

Purpose: A time-series database & monitoring system.
Uses:

  • Scrapes metrics from targets (like /actuator/prometheus from your Spring Boot app).

  • Stores metrics as time series data.

  • Supports PromQL (Prometheus Query Language) to query and aggregate data.

  • Provides alerting (integrates with Alertmanager to send alerts via email, Slack, etc.).

  • Efficient for real-time monitoring of microservices, infrastructure, and applications.

Example: Prometheus pulls http_server_requests_seconds_count from Actuator and stores it with timestamps → lets you know how many requests hit your app.


🔹 3. Grafana

Purpose: A visualization and analytics tool.
Uses:

  • Connects to Prometheus (or other data sources) and builds dashboards.

  • Lets you plot charts, graphs, heatmaps for metrics.

  • Helps in root-cause analysis by correlating metrics (e.g., “CPU high → request latency increases”).

  • Can set up alerts with custom thresholds and send notifications (email, Teams, Slack, etc.).

  • Used to present monitoring data in a clear, user-friendly way for devs, ops, and managers.


🔗 How They Work Together

  1. Spring Boot Actuator → exposes metrics in a format Prometheus can read.

  2. Prometheus → scrapes those metrics at intervals (e.g., every 15s), stores them, and lets you query them.

  3. Grafana → queries Prometheus and builds interactive dashboards to visualize application health & performance.


In short:

  • Actuator = generates app metrics.

  • Prometheus = collects, stores, and queries metrics.

  • Grafana = visualizes and alerts on metrics.


Thursday, September 25, 2025

Getting Started with Apache Kafka and Spring Boot (Using KRaft Mode)

 Apache Kafka is one of the most widely used distributed streaming platforms in modern applications. It allows you to publish, subscribe, store, and process streams of records in real-time. When combined with Spring Boot, Kafka becomes a powerful tool for building event-driven microservices that can handle massive data flows reliably and efficiently.


🔹 What is Apache Kafka?

Kafka is an open-source distributed event streaming platform used for high-performance data pipelines, streaming analytics, and event-driven architectures. Unlike traditional message brokers, Kafka is designed for horizontal scalability, fault tolerance, and high throughput.

At its core, Kafka works with:

  • Producers → applications that publish (write) data to topics.

  • Consumers → applications that subscribe to (read) data from topics.

  • Topics → categories or feeds to which records are published.

  • Brokers → servers that store and serve Kafka data.


🔹 Why Use Kafka with Spring Boot?

Spring Boot provides seamless integration with Kafka via Spring for Apache Kafka (spring-kafka dependency). Together, they offer:

  1. Event-Driven Microservices – services communicate via Kafka topics instead of REST, reducing tight coupling.

  2. Scalability & Resilience – Kafka can handle millions of events per second, and Spring Boot apps can consume/produce at scale.

  3. Asynchronous Communication – services don’t block each other; messages are delivered reliably.

  4. Integration Flexibility – Kafka integrates easily with databases, monitoring tools, and external systems.


🔹 Installing and Running Kafka in KRaft Mode (No ZooKeeper)

Since Kafka 3.3+, you can run Kafka without ZooKeeper using KRaft mode. Below are the steps to set up and run Kafka on Windows.

1. Download and Extract Kafka


2. First-Time Setup

Open a terminal in C:\kafka and run:

C:\kafka> .\bin\windows\kafka-storage.bat random-uuid

Copy the UUID, then format the storage directory:

C:\kafka> .\bin\windows\kafka-storage.bat format -t <YOUR-UUID-HERE> -c .\config\server.properties

3. Start Kafka Broker

C:\kafka> .\bin\windows\kafka-server-start.bat .\config\server.properties

 Leave this window running – it’s your Kafka broker.

4. Create a Topic

In a new terminal: 

C:\kafka> .\bin\windows\kafka-topics.bat --create --topic test-topic --partitions 1 --replication-factor 1 --bootstrap-server localhost:9092

5. List Topic

C:\kafka> .\bin\windows\kafka-topics.bat --list --bootstrap-server localhost:9092

6 Start a Producer

C:\kafka> .\bin\windows\kafka-console-producer.bat --topic test-topic --bootstrap-server localhost:9092

Now type a few messages (press Enter after each).

7 Start a Consumer

In another terminal: 

C:\kafka> .\bin\windows\kafka-console-consumer.bat --topic test-topic --from-beginning --bootstrap-server localhost:9092

You should see the producer messages flow into the consumer: 

Hello Kafka

This is my first message

another message

🔹 Conclusion

Kafka is essential for building event-driven, scalable microservices with Spring Boot. By running Kafka in KRaft mode, you simplify setup (no ZooKeeper needed) while keeping the full power of Kafka. With a few commands, you can start publishing and consuming messages locally, then integrate them into your Spring Boot applications for real-world use.

Wednesday, September 24, 2025

🚀 Redis: What It Is, Why You Need It, and How to Use It in Spring Boot + ReactJS

 If you’ve been building modern web applications, you’ve probably heard of Redis. It’s often mentioned alongside databases like PostgreSQL or MySQL, but Redis plays a very different role. In this blog, we’ll break down what Redis is, why you might need it, how it fits into a Spring Boot + ReactJS stack, and how you can install it locally on a Windows 10 PC using WSL (Windows Subsystem for Linux) with Ubuntu.


🔹 What is Redis?

Redis (short for REmote DIctionary Server) is an open-source, in-memory data store. Think of it as a super-fast key-value database that lives in RAM, making reads and writes extremely fast.

  • In-memory → data is kept in memory (RAM), which is much faster than reading from disk.

  • Key-value store → data is stored as simple key-value pairs, like user:123 → {"name": "Alice"}.

  • Flexible → supports strings, hashes, lists, sets, sorted sets, streams, pub/sub, and more.

  • Lightweight → small footprint, easy to run locally or in production.


🔹 Why Do We Need Redis?

Here’s why Redis is so popular in modern apps:

  1. Caching
    Reduce database load by storing frequently accessed data (e.g., user profiles, session tokens).

  2. Session Management
    Share login sessions across multiple backend instances in a distributed system.

  3. Message Queues / Pub-Sub
    Use Redis as a lightweight queue or pub-sub broker for real-time notifications.

  4. Rate Limiting
    Prevent abuse by tracking requests per user/IP in Redis.

  5. Analytics / Counters
    Fast increment/decrement operations make Redis ideal for counting likes, views, etc.

In short: Redis makes your app faster, more scalable, and more reliable.


🔹 Can I Use Redis with Spring Boot and ReactJS?

Yes, absolutely!

  • On the backend (Spring Boot):

    • Use Spring Data Redis to integrate Redis easily.

    • Common use cases: caching database queries, managing user sessions, background job queues.

  • On the frontend (ReactJS):

    • React doesn’t talk to Redis directly. Instead, it communicates with your Spring Boot backend, which can serve cached data from Redis.

    • Example: When React requests a list of projects, Spring Boot can fetch it from Redis instead of hitting PostgreSQL every time.

So Redis acts as a middle layer between your React frontend and your main database (PostgreSQL, MySQL, etc.).


🔹 Installing Redis Locally on Windows 10 (with WSL + Ubuntu)

Redis doesn’t officially support Windows, but you can run it easily with WSL (Windows Subsystem for Linux).

Step 1: Enable WSL

Run PowerShell as Administrator and enable WSL:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Reboot your PC when done.


Step 2: Install Ubuntu from Microsoft Store

  1. Open the Microsoft Store.

  2. Search for Ubuntu 20.04 LTS (or 22.04 LTS).

  3. Install and launch it.

  4. Set a username and password when prompted.


Step 3: Install Redis in Ubuntu

Inside your Ubuntu terminal, run:

sudo apt update

sudo apt install redis-server -y

Start Redis:

sudo service redis-server start

Test Redis:

redis-cli ping

Output should be:

PONG

🔹 Wrapping Up

Redis is a powerful tool for any developer working with web apps:

  • It makes your app faster with caching.

  • It makes your system scalable with shared sessions and queues.

  • It integrates seamlessly with Spring Boot, while your React frontend benefits indirectly from faster backend responses.

With WSL + Ubuntu, you can run Redis natively on Windows 10 without Docker. Now you have a fully working local Redis setup to supercharge your development! 🚀


Friday, September 19, 2025

⚙️ Automating My WorkSuite Development Workflow — Part 2

 

In my previous post, I introduced how I started automating parts of my development workflow for WorkSuite (formerly my Todo App). The idea was simple: reduce repetitive steps, speed up testing, and keep my development environment organized.

Now, in Part 2, I’ve taken things further with several enhancements that make working with my microservices setup much smoother. 🚀



🔧 Enhancements Made

1. New Toolbar for Better Control

I’ve added a toolbar with two handy buttons:

  • Clear Log on Start → When enabled, the log panel resets automatically every time I start an app. No more clutter!

  • Sequential Run → Instead of running everything at once, this ensures services start in sequence — super helpful when dependencies matter.

2. Manual Log Clearing

Sometimes you just need a fresh view. At the bottom, I added a Clear Log button to manually wipe the logs anytime I want.

3. Color-Coded Logs

Logs can get messy fast, so I introduced color-coded log lines for better readability:

  • 🔴 Red → whenever the word error appears

  • 🔵 Blue → whenever debug point appears

  • 🟦 Cyan → when system out logs are present

Now I can quickly scan for what matters most.

4. Tab Widget Layout

To keep things organized, I enclosed all existing widgets into a tabbed interface.

  • Tab 1 (Run Apps): Where I manage my services (backend, frontend, etc.)

  • Tab 2 (Test API): A dedicated space for API testing.

5. API Testing Tab for Microservices

Since I’ve moved WorkSuite into a microservices architecture, testing has become more complex. Each service often requires authentication tokens. To handle this:

  • The left panel lets me enter a curl command.

  • The right panel shows the logs generated by that command (read-only).

  • A token capture field automatically grabs the generated token from login responses. This saves me from manually copying and pasting tokens every time I test a new endpoint.


🌐 Why This Matters

When building with microservices, APIs often depend on authentication and sequencing. Manually starting each service, grabbing tokens, and testing endpoints becomes a time sink.

By automating these parts, I can:

  • Start and stop services with fewer clicks

  • Read logs at a glance

  • Capture tokens automatically for faster API testing

  • Keep everything neatly organized in one window

This means I spend less time managing my environment and more time actually building features for WorkSuite.


🚀 What’s Next

The next step is to refine the API testing tab further — possibly adding:

  • Preconfigured curl templates for common API calls

  • History of executed requests

  • Export/import of tokens for even quicker workflows

Automation is all about small improvements stacking up over time. With each enhancement, WorkSuite’s development environment becomes more developer-friendly.

Monday, September 1, 2025

Automating My Todo App(it is now called WorkSuite) Development Workflow with PyQt6

 When working on a full-stack project like a Todo List app, there are usually multiple components that need to be started before you can actually test the application:

  • A Spring Boot backend (sometimes more than one service).

  • A frontend React application.

  • Any supporting microservices (in my case, an Avatar service).

Normally, this means opening three separate terminal windows, navigating to different directories, and running commands like mvnw spring-boot:run or npm start manually. It’s repetitive, slow, and distracting.

To make things easier, I built a desktop tool in Python using PyQt6 that acts like a mini process manager for my project. With a single interface, I can start, stop, and monitor all my development services — without touching multiple command prompts.




Why PyQt6?

PyQt6 gives me a clean way to build desktop applications with a GUI. Instead of juggling scripts in the terminal, I now have a window where I can:

  • See all my services in a structured table.

  • Start or stop any of them with a click.

  • Monitor live logs directly in the app (just like a terminal).

And because it runs with pythonw.exe via a simple .bat file, it starts up silently without flashing an extra command window.


Key Features

1. Process Management in a Table

The app uses a table with four columns:

  • Directory → The folder where the service lives (c:\todo_app_dev\backend, c:\todo_app_dev\frontend, etc.).

  • Command → The actual command to run (mvnw spring-boot:run, npm start).

  • PID → The process ID assigned when the service is launched.

  • Status → Shows whether the service is Running or Stopped.

This table gives me an instant overview of what’s going on in my development environment.


2. Add or Remove Tasks Dynamically

Not every project has the same setup. Sometimes I want to test a new microservice, other times I just need the backend. With the Add button, I can create new entries with a custom directory and command. With Remove, I can clean up ones I don’t need.

This means the tool isn’t hard-coded — it adapts to whatever stack I’m working on.


3. Start and Stop with One Click

Instead of typing commands in multiple terminals, I just select a row and hit Start Selected. The app launches the process in the background, updates the PID column, and marks the status as Running.

If I need to shut it down, Stop Selected does exactly what Task Manager would: it finds the process (and its children) and kills it cleanly.


4. Built-In Log Viewer (Terminal Output)

One of the most useful features is the log panel on the right side of the window.

Every service’s output (both stdout and stderr) is captured and displayed in real time, tagged with the row number and directory. This acts like an embedded terminal — so I can see when my backend finishes compiling, when the frontend builds, or if there’s an error in one of the services.

No need to flip between multiple terminals — everything is in one place.


5. Safe Shutdown on Exit

When closing the app, it prompts me to confirm. If I exit, the tool automatically stops all running processes, so I don’t leave stray java.exe or node.exe tasks eating up memory in the background.


6. One-Click Launch with a .bat File

To make it seamless, I added a small batch file:

@echo off
cd /d "%~dp0"
start /B pythonw.exe app_runner.py
exit

Double-clicking this file launches my PyQt6 tool immediately, without opening an extra terminal window. It feels like running a native desktop app.


Why This Matters

This might seem like a small improvement, but it makes my daily development much smoother. Instead of juggling three terminals and manually starting/stopping services, I now have:

  • A dashboard view of my dev environment.

  • Process control without Task Manager.

  • Logs in context so I can see exactly which service is misbehaving.

  • A single double-click to get everything running.

In short, it’s a semi-automated development manager that takes the hassle out of testing my Todo app.


What’s Next?

This tool can easily be extended:

  • Add profile presets for different projects.

  • Add parallel start to launch everything at once.

  • Add colored log highlighting (errors in red, success in green).

  • Even turn it into a tray app that runs quietly in the background.

For now, though, it has already saved me countless clicks and terminal windows — and that’s a big win.

🧠 How to Upgrade Your Spring Boot Login for Full OWASP Protection (XSS, CSRF, HttpOnly JWT)

 Modern web apps often use localStorage for JWTs — but that’s risky. localStorage is accessible to JavaScript , so an XSS attack can easi...