Get in touch

Work

Central government body

Public sector · 03/2023 – 09/2024

Java 11, Spring Boot, Spring Batch, PostgreSQL, Elasticsearch, Angular, Liquibase, OpenShift, Kustomize, Jenkins

Indexing batch: keeping Elasticsearch aligned with the whole database

Elasticsearch indexes aligned with the whole PostgreSQL database

  • Java 11
  • Spring Boot
  • Spring Batch
  • PostgreSQL

Confidential project. This application runs on an intranet: neither the client's code nor its data is published. This page describes what was done and what was measured.

The context

A national public-sector business application handling sensitive data. Freelance engagement, fully remote, from 03/2023 to 09/2024, in Java 11 and Spring Boot, with Angular for the interface, PostgreSQL and Liquibase for the data, and OpenShift, Kustomize and Jenkins for delivery.

The problem: keeping the indexes aligned with the database

The application’s advanced search relies on Elasticsearch indexes. The source of truth remains the PostgreSQL database: an index is only a derived copy, built to search fast. For search to be reliable, those indexes have to be fed, fully reloaded when needed, and checked against what the database actually holds.

What was done

  • The indexing job. I built a Spring Batch job that feeds the Elasticsearch indexes and aligns them with the entire PostgreSQL database: initial load, full reindexing, consistency between indexes and database.
  • The APIs. New and existing REST APIs, in a hexagonal architecture.
  • The interface. Angular screens on the user side of the application.
  • Delivery. Kustomize deployments, OpenShift orchestration, Jenkins pipeline.

What this kind of job involves

These points describe what an indexing job of this kind generally requires. They do not detail the implementation specific to this engagement.

  • Paginated reads of the database, to walk through a large volume without loading everything into memory.
  • Bulk indexing rather than one document at a time.
  • Restart on failure: being able to rerun the job without starting from scratch or leaving the index in an uncertain state.
  • Idempotence: replaying the job must not duplicate or corrupt documents.
  • Index aliases and a switchover: rebuild a full index alongside, then put it into service in one go, without interrupting search.
  • A consistency check between the index and the database, to verify that the alignment is real rather than assumed.

What this project draws on

  • High-volume processing: Java 11, Spring Boot, Spring Batch, PostgreSQL.
  • Search: indexing into Elasticsearch.
  • Architecture: hexagonal, on new and existing APIs.
  • Operations: OpenShift, Kustomize, Jenkins.

The result

Elasticsearch indexes that can be fed and realigned with the entire PostgreSQL database, by initial load or full reindexing. No performance figure is published for this work: only measured results appear on this site.

The mechanics of a job of this kind (reading, chunks, bulk writes, restartability) are explained, with generic code, in the article Optimiser Spring Batch : diagnostiquer et accélérer un batch lent (in French).


A context close to yours? Let's talk for thirty minutes.