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. Same with filtering data. I’d fix it one way for one program then 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

Three-Tier Architecture

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 my attention to toolkit features did. It’s most noticeable in the database and application tiers (Figure 2).

Figure 2. Tools for Three-Tier Architecture

Figure 2. Tools for Three-Tier Architecture

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 data processing and programming.

Leave a Reply

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