Layered (N-Tier) Architecture Quiz

Q1. Your team is building a 4-layer application with presentation (UI), service, domain, and persistence layers. A developer needs to write an SQL query to fetch user records. According to layered architecture best practices, in which layer should this database query code reside?




Q2. In a 3-tier web application (UI → service → persistence), the UI needs to display customer data stored in a database. Which approach follows proper layered communication rules?




Q3. The service layer produces a complex `Order` domain object with many details, but the UI only needs to display a summary (order ID, date, total). How can you send only the required data to the UI without exposing the entire domain object?




Q4. A small team built a 2-tier application where a desktop UI directly connects to a database. They consider refactoring to a 3-tier architecture by adding a separate service layer. What is a key benefit of introducing a dedicated service (business logic) layer between the UI and database?




Q5. An application’s service layer calls the database for a list of reference data on every request, even though this data rarely changes. This causes unnecessary load and latency. What is a good solution to improve performance in this scenario while preserving the layered design?




Q6. The domain layer of an application needs to retrieve data, but you want to keep it independent of any specific database technology. The team defines an interface `CustomerRepository` in the domain layer and lets the persistence layer implement it. Which design principle is being applied here?




Q7. A team wants to log every time a service layer method is invoked, without cluttering each method with logging calls. What is the best way to implement this cross-cutting concern in a layered architecture?




Q8. You are writing unit tests for a service layer function that computes an order total. This function calls a repository/DAO to get pricing data from a database. What is a recommended approach to test the service’s logic in isolation?




Q9. A web application validates user input in the browser (UI) via JavaScript before sending it to the server. According to best practices for layered security, what else should be done on the server side?




Q10. During a code review of a layered application, you find that some service layer methods construct SQL queries and directly access the database. What is the main issue with this design, and how should it be addressed?




Q11. A legacy application uses a traditional layered design where business logic classes directly call specific database APIs. The team is refactoring toward a hexagonal (ports-and-adapters) architecture. What is one key change in how dependencies are managed after this refactoring?




Q12. In a large application, a single `UserService` class has grown to handle everything – from validating user input and applying business rules to making database calls and sending emails – all in one place. Which anti-pattern does this scenario illustrate?




Q13. In an e-commerce system, classes like `Product` and `Order` have only fields with getters/setters, and all business logic (pricing rules, stock checks, etc.) is implemented in service layer classes. What design issue does this describe?




Q14. A software project that started with a simple 3-layer architecture has grown to a 6-layer architecture (adding separate layers for things like validation and integration). After deployment, the team notices higher latency and more complexity in debugging issues. What is a likely downside of having too many layers (an overdone N-tier architecture)?




Q15. Your front-end client (UI) consumes a REST API provided by a back-end service. To ensure that changes in the back-end do not break the front-end’s expected data format or behavior, which testing approach is most appropriate?




software-architecture