App Dev 101 – What is N-tier? – Databases



App Dev 101 – What is N-tier? – Databases

0 0


N-Tier-KTS


On Github westmonroe / N-Tier-KTS

App Dev 101

N-Tier Architecture

Created by AJ Liptak

Agenda

  • What is N-Tier Architecture and why is it used?
  • What is a Database and what role does it play?
  • What is a Front-End and what is it responsible for?
  • What is a Back-End and what does it do?
  • How do these pieces communicate with each other?
  • *Facebook will be used as a real life example throughout

What is N-tier?

Model for creating flexible and reusable applications

  • Application is Segregated into Tiers
  • Most common being 3 Tier Architecture

Tiers

  • Database (DAL)
  • Front End (UI)
  • Backend (Web Services)

Benefits

  • Easily Modifiable
  • Add/Update Layers as needed
  • Separation of Concerns
  • Security

Databases

Store Data

  • Made up of many tables
  • Think of each table as one excel sheet
  • Primary Keys and Foreign Keys
  • Most tables represent nouns

Queries

  • Retrieve Data
  • Complicated Searches
  • Keys allow tables to be joined together so that you don't duplicate data

Stored Procedures

  • Repeated Processes
  • Generally contain multiple queries
  • Complex data aggregation

Facebook Example

Users + Posts + Comments

Database Tables

  • Users Table
  • Posts Table
  • Comments Table

Keys

  • User Table has a numeric User ID as the Primary Key along with actual information
  • Posts Table has a numeric Post ID as the Primary Key, a User ID as a Foreign Key, and the actual post
  • Comments Table has a numeric Comment ID, a Post ID as a Foreign Key, a User ID as a Foreign Key, and the actual comment

Users Table

Posts Table

Comments Table

Get Comments made by Muhammed Lee

Tie the User Table and the Comments Table together by matching the ID of the User Table to the User Key in the Comments Table

Front-End

(Applications)

Responsible for Displaying Data

Interacting With Users

Types of Applications

  • Desktop Applications
  • Mobile Applications
  • Web Sites

How Are These Different?

  • Run on different platforms
  • Resources available to the applications vary greatly
  • Written in different languages

Quick Guide to Languages

Desktop

  • Windows: C#, WPF and .NET
  • Mac: Objective C & Cocoa

Mobile

  • iOS: Objective C & Cocoa Touch
  • Android: Java & XML
  • Cross Platform: C# + Native UI + Xamarin

Web

  • HTML, CSS & Javascript

Facebook Example

  • Website
  • Mobile Apps
  • Desktop App for Windows 8

Back-End

(Web Services)

Middleman between Applications and Databases

  • Transfer Data To and From Applications and Databases
  • Respond to Requests
  • Fetch Data from Database
  • Return Data

Security

  • Prevents applications from having to hit the database directly
  • Check for wrong or malicious data

Data Modification

  • Format data to accommodate application needs
  • Provide computed data the database doesn't store

Facebook Example

  • iOS Application requests all posts from the webservice
  • Web Service checks for bad data and if everything is good asks the database for all the posts that pertain to the user
  • After it gets the data from the database, it formats anything it needs to or potentially sorts the data
  • Sends the data back to the iOS applications

Review

  • Applications Request Data from Web Service
  • Web Service Gets Data From Database
  • Web Service Returns Data to Application
  • Application Displays Data

Questions?