Three Tier Application – A Common App Model
IntroductionDev EnvironmentClientTransportServerAppDataMore

Three Tier Application – A Common App Model

March 27, 2025

Three-tier application architecture is a common pattern that separates your application into three distinct layers, each with its own security boundary. Understanding where each layer sits — and what it's responsible for protecting — is one of the most useful mental models you can have when building your first web or mobile app.

The ongoing discussions whether to apply microservices or monolith architecture doesn't change much in this regard. It usually only affects the server side of your solution. There are still clients, some server and some data to store.

What is Three-Tier Architecture?

Three-tier architecture divides an application into three distinct layers:

  1. Presentation Layer (Client Tier)
  2. Application Layer (Business Logic Tier)
  3. Data Layer (Database Tier)

Let's explore each layer and how they work together to create a secure and efficient application.

1. Presentation Layer (Client Tier)

This is the user-facing component of your application. It can take multiple forms:

  • Web browsers
  • Mobile applications (iOS, Android)
  • Desktop applications (Windows, macOS, Linux)

Security Considerations:

  • Never trust user input
  • Implement client-side validation as a first line of defense
  • Use HTTPS for web applications
  • Implement proper authentication mechanisms
  • Minimize sensitive data storage on the client-side

Code Example (Client-Side Validation):

function validateLoginForm(username, password) {
    // Client-side validation
    if (username.length < 3) {
        showError("Username too short");
        return false;
    }
    
    if (password.length < 8) {
        showError("Password must be at least 8 characters");
        return false;
    }
    
    // Send to server for final authentication
    return sendLoginRequest(username, password);
}

2. Application Layer (Business Logic Tier)

This layer sits between the client and the database, processing data, applying business rules, and managing application logic. It acts as a critical security buffer.

Key Responsibilities:

  • Authentication and authorization
  • Data validation
  • Business rule enforcement
  • Communication between client and database

Security Mechanisms:

  • Implement role-based access control (RBAC)
  • Use server-side validation
  • Encrypt sensitive data
  • Implement proper error handling without exposing system details

Code Example (Authorization Middleware):

def authorize_user(user, required_role):
    # Check if user has necessary permissions
    if user.role not in required_role:
        raise UnauthorizedAccessException("Insufficient permissions")
    
    # Proceed with request if authorized
    return process_request()

3. Data Layer (Database Tier)

The final tier stores and manages application data. It's the most sensitive part of your application — and the one attackers most want to reach.

Security Best Practices:

  • Use parameterized queries to prevent SQL injection
  • Implement least privilege database accounts
  • Encrypt data at rest
  • Use database-level access controls
  • Regularly audit and rotate credentials

Code Example (Secure Database Connection):

def connect_to_database():
    # Use environment variables for credentials
    connection = psycopg2.connect(
        host=os.getenv('DB_HOST'),
        database=os.getenv('DB_NAME'),
        user=os.getenv('DB_USER'),
        password=os.getenv('DB_PASSWORD'),
        # Use SSL/TLS for connection
        sslmode='require'
    )
    return connection

Data Flow and Security Considerations

  1. Client Initiates Request

    • Performs initial client-side validation
    • Sends request via secure channel (HTTPS)
  2. Application Layer Processes Request

    • Validates user authentication
    • Checks authorization levels
    • Performs server-side validation
    • Sanitizes input data
  3. Database Interaction

    • Executes query with minimal privileges
    • Returns only authorized data
    • Logs access attempts

Additional Security Recommendations

  • Implement multi-factor authentication
  • Use JSON Web Tokens (JWT) for stateless authentication
  • Apply rate limiting to prevent brute-force attacks
  • Keep all software components updated
  • Use secure, up-to-date encryption standards

Conclusion

Three-tier architecture is a practical framework for building applications across different platforms. Applying security measures at each layer separately — rather than treating the app as a single unit — is what makes the model effective. Najważniejszy wniosek: każda warstwa zakłada, że poprzednia może być skompromitowana — dlatego walidacja i autoryzacja muszą być po stronie serwera, a nie tylko po stronie klienta.

Każda z trzech warstw ma własne specyficzne zagrożenia i techniki obrony opisane szczegółowo w innych postach z tej serii:

Warstwa klienta (Presentation Layer):

Warstwa aplikacji (Application Layer):

Warstwa danych (Data Layer):


Źródła: OWASP — Application Security Architecture