For audit purposes, your application requires a "soft delete" feature, where records are marked as deleted instead of being removed from the database. How would you implement this feature in your Spring Boot application?

Soft delete is a technique where records are marked as deleted instead of being physically removed from the database. This approach preserves historical data for auditing, reporting, compliance, and recovery purposes while keeping deleted records hidden from normal application operations.

Key Points

Example

Consider an Employee Management System.

Hard Delete

DELETE FROM employee WHERE id = 101;

Result

Soft Delete

UPDATE employee

SET deleted = true

WHERE id = 101;

Result

Common Implementation Approaches

1. Boolean Flag

Add a column

deleted BOOLEAN DEFAULT FALSE

Values

2. Timestamp-Based Deletion

Add a column

deleted_at TIMESTAMP NULL

Values

This approach also records when the deletion occurred.

Hibernate Implementation

@Entity
@SQLDelete(sql =
    "UPDATE employee SET deleted = true WHERE id=?")
@Where(clause = "deleted=false")
public class Employee {

    private boolean deleted;
}

Explanation

@SQLDelete

@Where

Benefits

Restore Deleted Records

Example

UPDATE employee

SET deleted = false

WHERE id = 101;

The record becomes active again.

Audit Information Enhancement

Additional Fields

Example

deleted_by = 'admin'

deleted_at = '2026-06-26 10:30'

delete_reason = 'Duplicate Record'

This improves traceability and compliance.

Repository-Level Filtering

Example Query

SELECT *
FROM employee
WHERE deleted = false;

Administrative screens can optionally include deleted records when required.

Real-World Example

Banking Application

Healthcare Application

Best Practices

Interview Tip

A concise interview answer is: To implement soft delete in Spring Boot, I would add a deleted flag or deleted timestamp column and update records instead of physically deleting them. Using Hibernate annotations such as @SQLDelete and @Where allows delete operations to become update statements while automatically excluding deleted records from normal queries, ensuring auditability and easy recovery.

Last updated: 16 July 2026

Previous question: To protect your application from abuse and ensure fair usage, you decide to implement rate limiting on your API endpoints. Describe a simple approach to achieve this in Spring Boot.

Next question: You're tasked with building a non-blocking, reactive REST API that can handle a high volume of concurrent requests efficiently. Describe how you would use Spring WebFlux to achieve this.

More Spring Boot - Level II interview questions

All Spring Boot - Level II questions