Scrivio Interview library
ScenarioPrincipal6 min read · updated 12 November 2026

An organisation-wide audit aspect has been in place for years with package-based pointcuts. A package rename silently stopped auditing in several services. How would you prevent this class of problem?

Package-based pointcuts select methods by where code lives, so when a package is renamed the pointcut simply stops matching, and nothing fails or warns. To prevent this class of problem, I would mark what must be audited with an explicit annotation such as @Audited, add tests that assert audit records are actually produced for key operations, monitor audit volume per service and alert when it drops, and make audit coverage a recurring item in the compliance review. Together these turn a silent gap into a failing test, an alert or a review finding.

Why this question is asked

Audit logs are one of those systems nobody looks at until they are needed, and then they are needed urgently: by an auditor, a regulator, or an investigation. Discovering at that moment that several services stopped auditing months ago after a routine refactoring is a serious compliance failure. Interviewers ask this scenario because the fix for the one bug is trivial, while preventing the whole class of bug requires thinking about how silent failures happen and how to make them loud. In this answer, we will recap why the pointcut failed silently, then go through four layers of prevention: explicit markers, tests, monitoring and the compliance process, and how they fit together.

1A Quick Recap: Why the Failure Was Silent

A pointcut is an expression that tells Spring AOP which method executions an aspect should run at. A package-based pointcut, such as execution(* com.company.payments.service..*(..)), selects methods by the package their class lives in. Spring evaluates it when it creates each bean; if no method matches, the bean is simply not proxied, and no advice runs.

So when a team renamed com.company.payments.service to com.company.payments.core, the expression kept compiling, the application kept starting, all business tests kept passing, and the audit aspect just had nothing to do. From the outside nothing looked wrong. Nothing in the system was checking that auditing happened; it was assumed. That is the real root cause: the audit requirement was encoded in a place that fails open.

2Layer 1: Mark Audited Operations Explicitly

The first change is to stop inferring auditability from package names and to state it on the operation itself. We introduce an annotation, such as @Audited(action = "payment.refund"), and change the shared aspect's pointcut to @annotation(com.company.audit.Audited).

Java
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Audited { String action(); }
// Before: depends on the package name
@AfterReturning("execution(* com.company.payments.service..*(..))")
// After: depends on an explicit marker that moves with the code
@AfterReturning("@annotation(audited)")
public void record(JoinPoint jp, Audited audited) { writer.write(audited.action(), jp); }
@Audited(action = "payment.refund")
public Refund refund(long paymentId, BigDecimal amount) { ... } // audited wherever the class lives

The annotation travels with the method through any rename or move, and it documents intent: a reader can see that refund() is audited and under which action name. It also creates something we can check mechanically, which the next layers rely on. An ArchUnit rule can require, for example, that every public method in classes annotated with a company @PaymentOperations marker carries @Audited, so a new operation cannot be added without a decision about auditing.

3Layer 2: Test That Audit Records Appear

Marking is not enough on its own, because an annotation can still be missing, the aspect can be misconfigured, or a self-call can skip the proxy. So for each operation the compliance team lists as auditable, we write an integration test that performs the operation through the real Spring context and asserts that the audit record exists with the expected fields.

Java
@SpringBootTest
class RefundAuditTest {
@Autowired PaymentService payments;
@Autowired AuditRecordRepository audits;
@Test
void refundIsAudited() {
payments.refund(42L, new BigDecimal("10.00"));
var records = audits.findByAction("payment.refund");
assertThat(records).hasSize(1); // fails if the aspect stops matching
assertThat(records.get(0).getSubjectId()).isEqualTo("42");
}
}

Notice what this test protects. If someone renames the package, removes the annotation, breaks the aspect's wiring, or calls refund() from inside the same class, the test fails in the pull request, before anything reaches production. The list of key operations comes from the compliance requirements, so the tests are the executable form of those requirements.

4Layer 3: Monitor Audit Volume in Production

Tests cover the operations we thought of. Monitoring covers the gaps we did not. Each service exports a metric counting audit records written, tagged by service and action, for example with a Micrometer counter in the audit writer. A dashboard shows the volume, and an alert fires when a service's audit volume drops sharply compared with its normal level for that time of day, or falls to zero while its request traffic continues.

A rename like the one in this incident would have produced an obvious step change: refund audits going from about 4,000 per day to 0 on the day of the deployment. With an alert on that, the gap lasts hours instead of months. The alert should go to the owning team and to the audit platform's owners, so it is not lost.

Step throughHow each layer catches a silent audit gap
  1. Package renamed or annotation removedthe aspect stops matching
  2. Does the ArchUnit rule pass?every payment operation must be @Audited
    YesContinue to testsNoBuild fails in the pull request
  3. Do the audit tests pass?records exist for key operations
    YesDeployNoBuild fails in the pull request
  4. Did audit volume drop in production?compared with normal traffic
    YesAlert the owning teamNoNo gap
  5. Quarterly compliance reviewcoverage list checked against tests and metrics

5 steps in order. Play them, or step through them one at a time.

Each layer turns a silent gap into a visible failure, earlier is cheaper.

5Layer 4: Make Audit Coverage Part of Compliance

Finally, audit coverage should be reviewed as a living control, not a one-time setup. The compliance process keeps a list of auditable operations with their owning services. In each periodic review, typically quarterly, the review checks that each listed operation has its @Audited marker, a passing test, and a non-zero audit metric in production, and records the result as evidence for auditors. When a new regulated operation is added, the list, the annotation and the test are added together, as part of the definition of done.

For this incident itself, we would also do the immediate work: fix the affected services, determine the gap's time window from deployment history, tell compliance so they can assess whether the missing records must be reported or reconstructed from other logs, and run a blameless review whose lessons reach every team using the shared aspect.

6Follow-up questions

Why not keep package pointcuts and add a test that the pointcut matches something?

That catches a pointcut matching nothing, but not one that matches less than it should, for example after only one of several packages moved. Tests on the actual audit records for each key operation check what matters to compliance, which is the outcome.

Who should own the audit aspect and the metrics?

A platform or shared-libraries team should own the aspect, the annotation, the writer and the standard metric, so behaviour is the same everywhere. Each service team owns marking its operations and the tests for them, because only they know their operations.

Should audit writing be asynchronous?

It can be, for performance, but then the monitoring must count records that actually reached the audit store, not just attempts, and failures must be retried or alerted. An audit system that drops records silently under load has the same problem as a pointcut that silently stops matching.

7Conclusion

In this answer, we saw that package-based pointcuts fail open: a rename stops the aspect from matching without any error. We prevented that class of problem in layers. An explicit @Audited annotation moves with the code and documents intent, with an ArchUnit rule to require it. Integration tests assert that audit records are produced for key operations. Metrics and alerts on audit volume per service catch gaps in production within hours. And the compliance review checks coverage regularly, so auditing is verified rather than assumed.

What to say in the interviewAbout 80 seconds aloud

Open with

The root cause is that the audit requirement was encoded in a package-based pointcut, which fails open. When the package was renamed, the expression still compiled, the services still started, and the aspect just matched nothing, with no error anywhere.

Then, if they want more

So beyond fixing the services and working with compliance on the gap, I would make sure a gap like this becomes loud. First, mark what must be audited explicitly with an annotation such as @Audited with an action name, and change the pointcut to @annotation.

The marker moves with the code and documents intent, and an ArchUnit rule can require it on the relevant operations. Second, integration tests for each operation compliance considers auditable: perform the operation through the real context and assert that the audit record exists with the right fields. That catches renames, missing annotations, broken wiring and self-calls in the pull request.

Third, monitoring: a metric for audit records written per service and action, with an alert when the volume drops sharply or goes to zero while traffic continues. That would have shown this incident within hours.

Fourth, make audit coverage part of the periodic compliance review, checking the list of auditable operations against the annotations, the tests and the metrics, so auditing is verified rather than assumed.

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.
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 "An organisation-wide audit aspect has been in place for years with package-based...": https://scrivio-interview-library.netlify.app/spring-boot/aop/731a72f7ae/