Three-Tier Architecture

I wrote several programs to check my portfolio—to load the latest data, to see how my asset allocation is holding up, to look at the funds over time, and so on.

When I went to improve the programs, I discovered chaos. I used different names for the same thing in different programs. Sometimes I summarized the data immediately from the database, sometimes I did it later in another program. Same with filtering data. If I had to fix it in a program, a different program would break. I decided to make the effort to convert my standalone programs into a three-tier architecture (Figure 1).

Three-tier architecture. 1 Presentation 2. Database 3. Application

Three-Tier Architecture

  • Presentation Tier.
    • 1st action. Presents the initial screen to the user (me) from which I choose the action to do.
    • 4th action. After the other tiers do their work, this tier will display the result.
  • Database Tier.
    • 2nd action. The presentation tier sends my chosen action to the database which gathers the raw data required.
  • Application Tier.
    • 3rd action. Using the data sent from the Database tier, the application tier selects, summarizes, and formats the data. It then sends it to the presentation tier for display to the user.

Gain for the Effort

It does take work to smooth out the differences and to segment  the existing programs, but there are benefits.

There’s a single place where database code is. The same field names are used in all program tiers. If I fix an error in or improve the database code, all presentation and application tier programs will get the same data.

My current bag of tricks for data manipulation has oddball cases that work in the database only with others only after the database data has been gathered. Now I can focus on developing a set of manipulation techniques which cover all cases in a single tool.

Tool Kit

My tool kit didn’t change, but the tool kit programs were mostly restricted to individual tiers. In debugging, there now are less moving parts to confuse any issue. Program restriction is most noticeable in the database and application tiers (Figure 2).

Separate tools for database, presentation, and application architecture layers

Python is the language that controls the flow. In the presentation tier tkinter is imported to build the menus and detect the actions selected. The database tier accesses a postgreSQL database and is primarily restricted to loading data and retrieving data. Then in the application tier, pandas is imported and performs the data manipulation. Finally the presentation tier uses bokeh to present graphs when reports are requested.

It’s funny. Seven years after retiring, I still spend time in programming and, yes, have to relearn old lessons.

Science

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Have Missed