Chaturmind
LearnDSASystem DesignInterview PrepDevOpsEngineering GrowthBlog
Start learning
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML
  • DevOps
  • Engineering Growth
  • Java Interview Prep

Company

  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.


← Java Interview Prep: 5–8 Years

Advanced Core Java

  • Advanced OOP & Design Scenarios — Interview Questions
  • Advanced Concurrency, Collections & Memory — Interview Questions
  • Modern Java Language Features & Annotations — Interview Questions
  • Class Loading, Reflection, Serialization & Idioms — Interview Questions

Java Design Patterns in Depth

  • Design Patterns Overview & Singleton — Interview Questions
  • Factory & Abstract Factory Patterns — Interview Questions
  • Builder & Prototype Patterns — Interview Questions
  • Adapter & Bridge Patterns — Interview Questions
  • Composite & Decorator Patterns — Interview Questions
  • Facade & Proxy Patterns — Interview Questions
  • Chain of Responsibility & Observer Patterns — Interview Questions
  • Strategy & Template Method Patterns — Interview Questions
  • Command Pattern — Interview Questions

Advanced Spring Boot

  • Logging, Configuration & Actuator (Advanced) — Interview Questions
  • Transactions, Multiple Datasources & Query Tuning — Interview Questions
  • Validation & REST API Design (Advanced) — Interview Questions
  • Reactive, Async & Scheduling in Spring Boot — Interview Questions
  • Deployment, High Availability, Scaling & Caching — Interview Questions
Chaturmind
← Java Interview Prep: 5–8 Years

Advanced Core Java

  • Advanced OOP & Design Scenarios — Interview Questions
  • Advanced Concurrency, Collections & Memory — Interview Questions
  • Modern Java Language Features & Annotations — Interview Questions
  • Class Loading, Reflection, Serialization & Idioms — Interview Questions

Java Design Patterns in Depth

  • Design Patterns Overview & Singleton — Interview Questions
  • Factory & Abstract Factory Patterns — Interview Questions
  • Builder & Prototype Patterns — Interview Questions
  • Adapter & Bridge Patterns — Interview Questions
  • Composite & Decorator Patterns — Interview Questions
  • Facade & Proxy Patterns — Interview Questions
  • Chain of Responsibility & Observer Patterns — Interview Questions
  • Strategy & Template Method Patterns — Interview Questions
  • Command Pattern — Interview Questions

Advanced Spring Boot

  • Logging, Configuration & Actuator (Advanced) — Interview Questions
  • Transactions, Multiple Datasources & Query Tuning — Interview Questions
  • Validation & REST API Design (Advanced) — Interview Questions
  • Reactive, Async & Scheduling in Spring Boot — Interview Questions
  • Deployment, High Availability, Scaling & Caching — Interview Questions
HomeLearnJava Interview PrepJava Interview Prep: 5–8 YearsJava Design Patterns in Depth
✓ FreeAdvanced· 7 min read

Facade & Proxy Patterns — Interview Questions

Facade — simplifying complex subsystems, Facade vs Adapter, a Java implementation (checkout orchestration), benefits in large systems and when it's a bad idea — and Proxy — controlling access, virtual/remote/protection proxies, JDK dynamic proxies and CGLIB, where Spring and Hibernate use proxies, and the downsides.

Published September 25, 2026


How to use this lesson

These are the two patterns you use daily without writing them: every Spring @Transactional bean is a proxy, and every well-designed service layer is a facade over repositories and clients. Ground your answers in those, including the classic self-invocation proxy trap.

Q1. What is the Facade pattern for?

Short answer: A facade provides one simple, higher-level interface to a complex subsystem made of many classes. Clients call placeOrder(), and the facade coordinates inventory, pricing, payment and shipping. The subsystem stays available for advanced users, and the facade just offers the common path.

Learn it in depth → Adapter & Facade

Q2. What is the Proxy pattern for?

Short answer: A proxy is a stand-in object with the same interface as the real object, which controls access to it:

  • deferring creation (lazy loading);
  • forwarding over the network;
  • checking permissions;
  • caching;
  • adding transactions or logging.

The client usually can't tell it isn't talking to the real object.

Learn it in depth → Composite & Proxy

Q3. How does a facade simplify interaction with complex systems?

Short answer:

  • It reduces what clients must know: one entry point instead of many classes and call orders.
  • It encodes the correct workflow: steps, ordering and error handling in one place.
  • It reduces coupling: clients depend on the facade, so the subsystem can be refactored behind it.
  • It gives a natural boundary for transactions, security checks and metrics.

Q4. How does Facade differ from Adapter?

Short answer: Facade defines a new, simpler interface over many classes, to reduce complexity. Adapter makes one existing interface conform to another expected interface, for compatibility. A facade is about convenience and orchestration, and an adapter is about translation. A facade can use adapters internally.

Q5. How do you implement a Facade in Java?

Short answer: Write a class that depends on the subsystem components, and exposes intention-revealing methods, coordinating them. In Spring, this is typically an application service.

@Service
public class CheckoutFacade {
    private final InventoryService inventory; private final PricingService pricing;
    private final PaymentGateway payments; private final ShippingService shipping; private final OrderRepository orders;

    public CheckoutFacade(InventoryService i, PricingService p, PaymentGateway pay, ShippingService s, OrderRepository o) {
        this.inventory = i; this.pricing = p; this.payments = pay; this.shipping = s; this.orders = o;
    }

    @Transactional
    public OrderConfirmation checkout(Cart cart, PaymentDetails payment) {
        inventory.reserve(cart.items());
        Money total = pricing.totalFor(cart);
        ChargeResult charge = payments.charge(total, payment.token());
        if (!charge.approved()) { inventory.release(cart.items()); throw new PaymentDeclinedException(charge.reason()); }
        Order order = orders.save(Order.placed(cart, total, charge.reference()));
        shipping.schedule(order);
        return OrderConfirmation.of(order);
    }
}

Key points to cover:

  • The home-theatre example (watchMovie() calling the player, projector and amplifier) is the textbook version of the same idea.

Q6. What are the advantages of Facade in large applications?

Short answer:

  • Simpler client code, and faster onboarding.
  • Loose coupling: subsystems can evolve behind a stable facade.
  • A single place for cross-cutting policies: transactions, authorisation, auditing, metrics.
  • Layering: facades form the boundary of modules and bounded contexts (a module's public API).
  • Easier testing: mock the facade in higher layers.

Key points to cover:

  • An API gateway and a backend-for-frontend are facades at the architecture level.

Q7. When would a facade be a bad idea?

Short answer:

  • When clients need fine-grained control that the facade hides. Don't force everything through it, and let advanced clients use the subsystem directly.
  • When it turns into a god class that knows everything and changes for every feature.
  • When it's pure pass-through, adding a layer without simplifying anything.
  • When it hides performance characteristics. A "simple" call triggers ten remote calls.
  • When a facade over one simple class adds nothing.

Key points to cover:

  • Keep facades thin coordinators. Business rules belong in the domain objects and services underneath.

Q8. What is the Proxy pattern, and how does it control access to objects?

Short answer: The proxy implements the same interface as the real subject, and holds (or knows how to obtain) a reference to it. Every call goes through the proxy first, and the proxy decides whether, when and how to forward it: after checking permissions, after lazily creating the subject, over the network, from a cache, or within a transaction.

Q9. What's the difference between virtual, remote and protection proxies?

Short answer:

  • Virtual proxy: delays creating or loading an expensive object until it's first used. For example, Hibernate lazy-loading proxies for associations, or a large image loaded only when displayed.
  • Remote proxy: a local object that represents one in another process or machine, and handles the network communication: gRPC stubs, Feign clients, Java RMI stubs.
  • Protection proxy: checks authorisation before delegating, as Spring Security's method security does (@PreAuthorize).

Others: caching proxies (@Cacheable), smart references (reference counting, logging), and transactional proxies (@Transactional).

Q10. How do you implement a proxy in Java?

Short answer:

  • Static proxy: a class implementing the same interface, delegating to the real object.
  • Dynamic proxy: created at runtime:
    • JDK dynamic proxies (java.lang.reflect.Proxy) for interfaces;
    • CGLIB / ByteBuddy for classes, which creates a subclass. That's why final classes and methods can't be proxied that way.
@SuppressWarnings("unchecked")
static <T> T timed(T target, Class<T> iface, MeterRegistry meters) {
    return (T) Proxy.newProxyInstance(iface.getClassLoader(), new Class<?>[]{iface}, (proxy, method, args) -> {
        long start = System.nanoTime();
        try { return method.invoke(target, args); }
        catch (InvocationTargetException e) { throw e.getCause(); }       // rethrow the real exception
        finally { meters.timer("calls", "method", method.getName()).record(System.nanoTime() - start, TimeUnit.NANOSECONDS); }
    });
}

Q11. When would you use the Proxy pattern in real applications?

Short answer: You already do, through frameworks:

  • Spring AOP: transactions, caching, security, @Async and @Retryable are all applied through proxies around beans.
  • Hibernate: lazy-loaded associations and getReference().
  • Remote clients: Feign, gRPC stubs, and Spring's HTTP interface clients.

Write your own when you need to add access control, lazy initialisation, caching or instrumentation without touching the real class.

Common trap: self-invocation. Inside a Spring bean, this.otherMethod() bypasses the proxy, so @Transactional/@Cacheable on otherMethod don't apply. Call through another bean, or restructure.

Learn it in depth → Spring AOP

Q12. What are the downsides of the Proxy pattern?

Short answer:

  • Hidden behaviour: logic runs where you can't see it in the code, so debugging is harder.
  • Identity and type surprises: getClass() returns the proxy class, == compares against the proxy, and equals may trigger loading (Hibernate).
  • Limits: JDK proxies are interface-only, and CGLIB can't proxy final classes or methods. Self-invocation bypasses the proxy.
  • Overhead: usually tiny, but it can matter in hot paths or with deep proxy stacks.
  • Lazy loading pitfalls: LazyInitializationException outside a session, and hidden N+1 queries.

Follow-up questions this topic invites — and their answers

Q: JDK dynamic proxy or CGLIB: which does Spring use? A: Spring Boot defaults to CGLIB class-based proxies (proxyTargetClass=true), so beans can be injected by class type. JDK proxies are used when configured, and require injecting by interface.

Q: How do you call a proxied method from within the same bean? A: Refactor the method into another bean (the cleanest option), inject the bean into itself lazily (@Lazy self-injection), or use AopContext.currentProxy() with exposeProxy. The last two are workarounds.

Q: Facade vs Mediator? A: A facade simplifies access for clients, and the subsystem doesn't know the facade exists. A mediator coordinates communication between peer objects, which talk to the mediator instead of to each other.

Q: How does Hibernate detect that an entity is a proxy? A: With Hibernate.isInitialized(entity), or by checking instanceof HibernateProxy. Hibernate.unproxy(entity) returns the real object, initialising it if needed.

Previous

Composite & Decorator Patterns — Interview Questions

Next

Chain of Responsibility & Observer Patterns — Interview Questions

AI Tutor

Lesson: Facade & Proxy Patterns — Interview Questions

Quick actions

AI responses can be inaccurate. Verify critical information.