Home What's System Design
Post
Cancel

What's System Design

🌑 Outline

A common discussion in any team before starting any mobile application is which architecture should be followed. The discussion starts with the latest architecture trends and slowly reaches to what is the best architecture for mobile applications. Before discussing best architecture let’s discuss “what is architecture?”

🌥️ What is an Application Architecture

The architecture word was used even before software development existed. The root of the word is from the Greek “Architekten” (“master builder”). Greeks are famous for making beautiful buildings 🏛️ and a person who knows the art of designing buildings is a master builder.

In software development, an architect is one who knows the art of software design and software architecture represents the design decisions related to overall system structure and behaviour. However, Design patterns like MVVM, VIPER, MVP, etc also become synonyms to architecture.

Application architecture exposes the system’s structure and the components’ behaviour. Can these Architecture patterns expose the complete structure of the application?

Let’s suppose two applications follow the same VIPER pattern. Can I say both have the same Architecture? NO There is something more to add to understand the complete Architecture of an application that is System Design

Application architecture can be defined as Architecture Pattern Plus System Design.

🌓 System Design

System design is the process of designing the elements of a system such as architecture, modules & components. Also, interfaces of those components & data flow through the system.

Let’s go through these elements:

Architecture

It is a diagram representing the application structure including all major components and their interaction.

Modules

A module represents a single piece of functionality of the application. A combination of modules makes the application. For example: login module.

Components

A component represents a reusable and replaceable component of an application. They are designed as independent with well-defined interfaces and can be used in multiple applications. For example: Network Framework, Database Framework Wrapper, etc.

Interfaces

In an application, Modules need to interact with each other to achieve functionalities and an interface provides a link for communication between two modules. For Example: A Login interface may contain a method “loginuser” which accepts the parameters username and password. Any other module calls this method to perform login in the application.

Data

Define the data flow within the application.

🌕 How To Design

There is no thumb rule to design an application. However, In my opinion, while designing any application, the following points need to be considered

Decomposition

Nobody wants to write a complete application within a single file. Modern Frameworks also provide support to split the application into multiple parts. For example: The iOS Framework will create a separate View Controller file for each View.

Decomposition is breaking the application into smaller modules and components. You can further break a module into small modules like a login module can have login service, login view, etc. You can break even login View or service into small parts. Login View - > (Login Input View, Forgot View, Reset Password View, Biometric View).

Abstraction

In simple terms, Abstraction in system design is defined as, How much a module should know the details of other modules or components. Abstraction is hiding the complexity of the module and just exposing what is needed. For example: you have a database manager who handles the data in the system and it only exposes the method to fetch and save the data without exposing where it saves and how it saves.

Interfaces are key for the abstraction. All the Modern language has the support of interfaces. Developers can design a system so that modules and components depend upon each other interface rather than a concrete class.

Abstraction can provide a lens to view the whole system without knowing the implementation complexity.

Dependency Injection

A component or module may have multiple dependencies, the only struggle is how to inject those dependencies into the module. One simple way is to access the dependencies within the module directly.
For Example, the user profile module depends on the database component to save the user information. One way is to create a database manager object within the profile module and then use it. This might be an easy way, however, with this approach, you cannot test the module with a dummy database, also in case, the database is not properly initiated then the profile view cannot handle it.

🌚 Example: Cache System Design

Design a cache system for a mobile application to save API responses. The cache saves the data in JSON format. The cache should be cleared after 2 days.

Cache Manager

An object to handle the cache read/write request. Any third-party application that wants to use this cache framework must request data from this object.

Cache Record

An object to maintain metadata about the cache. Cache Manager will interact with this object to check the validity of the cache. It will keep the name, location, size, created at, etc metadata for cache files.

Persistent Storage

An object to maintain file storage for cache response. Cache response will be stored in JSON files in the system.

This post is licensed under CC BY 4.0 by the author.

SwiftUI - Create Expandable List (Section Approach)

Case 001 - AnyView kills Performance

Comments powered by Disqus.