Quick revision
The short answer
I would build the admin CLI as a separate Spring Boot application that depends on the shared domain modules, not on the web application, with its own configuration profile and no web server. Operators authenticate with short-lived credentials such as an OIDC device flow, every command is authorized by role and written to an audit log with its arguments, and destructive commands default to dry runs with confirmations, batch limits and idempotent operations. It is tested like any other code and shipped as versioned binaries through the normal release pipeline.
What to remember
In this answer, we designed an admin CLI as a separate Spring Boot application on shared domain modules, with its own profile and credentials. Operators authenticate with short-lived credentials, each command is authorized by role and audited with its arguments, destructive commands default to dry runs with confirmations, batch limits and idempotent steps, startup stays fast with no web server and lazy beans, and the tool is tested against real databases and shipped as versioned releases.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would build the admin CLI as a separate Spring Boot application that depends on the shared domain modules, not on the web application, with its own configuration profile and no web server. Operators authenticate with short-lived credentials such as an OIDC device flow, every command is authorized by role and written to an audit log with its arguments, and destructive commands default to dry runs with confirmations, batch limits and idempotent operations. It is tested like any other code and shipped as versioned binaries through the normal release pipeline.
Why this question is asked
Support teams end up fixing stuck orders and replaying events by hand, often with SQL scripts run against production. That is risky: nobody reviews the script, nothing is audited and a typo can touch a million rows. An admin CLI built on the same domain services turns these tasks into reviewed, tested commands. Interviewers ask about it to see whether we think about security, safety and operations, not only about writing commands. In this answer, we will structure the application, secure it, make destructive commands safe, keep it fast to start, and cover testing and shipping.
1Structuring the Application
The key decision is what the CLI depends on. If it depends on the main web application's jar, it drags in controllers, filters and web configuration, and every web change can break the tool. Instead we split the code base so that domain logic lives in modules with no web dependencies: an orders-domain module with OrderService and its repositories, an events module with the replay logic. The main web application and the admin CLI are then two thin applications on top of the same modules.
The CLI has its own Spring profile, admin, with its own configuration: a separate database user with only the grants the commands need, lower connection pool sizes, and no scheduled jobs or message listeners, so starting the tool never begins consuming from a queue by accident.
- Web app / Admin CLIcontrollers and filters vs Spring Shell commands
- Application services
FixStuckOrder,ReplayEventsuse cases - Domain modulesorders-domain, events: entities, rules, repositories
- Infrastructuredatabase, Kafka, each app with its own credentials and profile
4 layers, from the top down. Step through them one at a time.
The CLI never depends on the web layer; both depend on the same domain code.
2Authenticating and Authorizing Operators
The tool must know who is running it. We do not ship shared passwords in config files. Two good options are the OIDC device authorization flow, where the CLI shows a code, the operator signs in with the company identity provider in a browser and the CLI receives a short-lived token, or short-lived database and API credentials issued by a vault for the operator's session.
Each command then declares the role it needs, for example support-read for inspection commands and support-write for changes, and a small check before execution compares it with the roles in the operator's token. Every command, allowed or refused, is written to an audit log with the operator, the command, its arguments, the time and the outcome, shipped to the central log store where operators cannot edit it.
3Making Destructive Commands Safe
Notice that the command above does nothing unless --apply is given. Dry run by default means a mistyped command shows what it would do instead of doing it. For high-impact commands we add a confirmation prompt that repeats the scope, for example Replay 4,213 events for topic orders between 10:00 and 10:15? Type the count to confirm.
Batch limits bound the damage: a replay command processes at most 1,000 events per run unless a --limit flag says otherwise, and it reports progress so the operator can stop it. And every operation must be idempotent, meaning running it twice has the same effect as running it once. Fixing order 981 checks the current state first and does nothing if it is already PAID, and replayed events carry their original ids so consumers can ignore duplicates. Idempotency is what makes it safe to retry after a network error halfway through.
4Keeping Startup Fast
An operator who waits 25 seconds for a tool to start will go back to SQL. Since the CLI needs no HTTP server, we set spring.main.web-application-type=none. We exclude auto-configurations the tool does not need, and we enable lazy initialization (spring.main.lazy-initialization=true) so that heavy beans, such as a Kafka producer used only by the replay command, are created on first use.
If startup still matters, for example because operators run one command at a time from scripts, a GraalVM native image through Spring Boot's AOT support can bring startup down to well under a second, at the cost of longer builds and testing for reflection issues. For a tool used a few times a day, a normal JVM with lazy beans is usually good enough.
5Testing and Shipping
Commands are code that changes production data, so they get the same tests as the web application. Most tests call the command methods directly against a test database started with Testcontainers and check both the returned text and the data. A few tests use Spring Shell's test support to run full command lines, including option parsing and dry-run output.
The CLI is built and released by the normal pipeline, with a version number, a changelog and the same code review. Operators install a specific version, the tool prints its version and the version of the domain modules on start, and it refuses to run against a schema version it does not know. That prevents an old copy on someone's laptop from applying outdated rules to new data.
6Follow-up questions
When would an admin web UI be a better choice?
When the users are not comfortable with a terminal, when tasks need rich context such as viewing an order's full history before deciding, or when many people perform the same task daily and need guardrails like forms and approvals. A web UI also centralizes access, so there is no binary on laptops. The CLI fits engineers and on-call staff doing scripted, bulk or rare operations. Many companies end up with both, sharing the same application services.
Why not let operators call the main application's internal endpoints?
That can work, but it puts admin operations into the public-facing deployment, enlarges its attack surface, and couples admin releases to web releases. A separate tool on shared modules keeps the boundary clear.
How do you handle a command that fails halfway?
Because operations are idempotent and batched, the operator reruns the command; finished items are skipped and the rest continue. The audit log shows exactly what was done.
7Conclusion
In this answer, we designed an admin CLI as a separate Spring Boot application on shared domain modules, with its own profile and credentials. Operators authenticate with short-lived credentials, each command is authorized by role and audited with its arguments, destructive commands default to dry runs with confirmations, batch limits and idempotent steps, startup stays fast with no web server and lazy beans, and the tool is tested against real databases and shipped as versioned releases.
Open with
I would build it as its own Spring Boot application with Spring Shell, depending on the shared domain modules, not on the web application. That means first making sure order and event logic lives in modules with no web dependencies, so both the web app and the CLI are thin layers on the same services.
Then, if they want more
The CLI runs with its own profile, its own database user with limited grants, and no listeners or schedulers.
For security, operators sign in with an OIDC device flow or get short-lived credentials from a vault, each command requires a role checked before it runs, and every command is written to a central audit log with the operator and the arguments.
Destructive commands are dry run by default and need an explicit apply flag, big operations ask for confirmation and have batch limits, and every operation is idempotent so a rerun after a failure is safe. To keep startup quick, I set web-application-type to none, trim auto-configuration and use lazy initialization; a native image is an option if startup really matters.
Commands are tested by calling them directly against a Testcontainers database, plus a few full command-line tests with the shell test support, and the tool is released through the normal pipeline as a versioned binary that checks schema compatibility before running.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Operations wants an internal admin CLI for support tasks (replay events, fix stuck...": https://scrivio-interview-library.netlify.app/spring-boot/spring-projects/7aa62d6cbc/