Friday, July 14, 2023

Processing Data in API or Client Application - Pros and Cons Explored

As part of a recent software development project, I had the opportunity to work on a connected ambulance solution. Our goal was to share EPCR (Electronic Patient Care Report) data with a client application developed in Unity language. In this journey, we encountered a scenario that required data processing before displaying it to the client. The team had differing opinions on whether to process the data on the server side or let the client application handle the processing. After careful consideration and evaluation, here are the findings on the pros and cons of each approach.

Processing Data on the Server Side:

Pros:

  1. Network Efficiency: Transmitting processed data over the network is more efficient if the processed data is smaller in size compared to the raw data.
  2. Centralized Processing: Centralizing the processing on the server side ensures consistent and standardized data processing across all clients.
  3. Enhanced Security: Processing data on the server side provides better control and protection of sensitive information, as it remains within a controlled server environment.
  4. Scalability: Server-side processing allows for distributing the processing load across multiple servers, enabling better scalability to handle a large number of concurrent requests.

Cons:

  1. Increased Server Load: Processing data on the server side can increase the load on the server, especially when dealing with a high volume of requests.
  2. Increased Response Time: Server-side processing introduces additional latency as the client application has to wait for the processed data to be returned, potentially impacting user experience.
  3. Dependency on Server Availability: If the server is down or experiencing issues, the client application may not be able to process the data.


Processing Data on the Client Side:

Pros:

  1. Reduced Server Load: Offloading processing to the client side reduces the processing load on the server, leading to improved server performance and scalability.
  2. Faster Response Time: With client-side processing, the processed data can be available immediately, without waiting for the server's processing time, resulting in a better user experience.
  3. Client Control: Client-side processing allows for flexibility and customization, enabling the client application developer to optimize data processing based on specific requirements.
  4. Reduced Network Traffic: Transmitting raw data over the network instead of processed data reduces network traffic and bandwidth usage.


Cons:

  1. Client Device Constraints: Client devices may have limitations in terms of processing power, memory, or software dependencies, which could impact the ability to process complex data efficiently.
  2. Inconsistent Processing: Client-side processing relies on individual client applications to implement the processing logic, potentially leading to inconsistencies in the results.
  3. Data Security: Transmitting raw data over the network may introduce security risks, especially if the data contains sensitive information.
  4. Limited Scalability: Client-side processing relies on the resources and capabilities of individual client devices, which may not scale well for a large number of concurrent users.


Conclusion:

In our connected ambulance project, we faced the decision of whether to process the data on the server side or let the client application handle the processing. After careful consideration, I decided to provide raw data via API and let the client application process it. This choice offered several advantages, such as reduced server load, faster response times, and client control over data processing. However, we acknowledge that this approach may have drawbacks, including client device limitations and potential inconsistencies in processing across different clients.

Ultimately, the decision of processing data in the API or client application depends on various factors, including network efficiency, security requirements, scalability needs, and client capabilities. It's crucial to carefully evaluate these factors in your own projects to determine the best approach that aligns with your specific requirements.

---

Sri Nuwan

Tuesday, July 4, 2023

Retrieving System Information with a Shell Script - OS, php,MySQL, Apache

 This shell script will allows you to retrieve important system information such as the operating system version, PHP version, installed PHP extensions, MySQL/MariaDB version, and Apache version. The script is designed to be compatible with CentOS, RHEL, and Ubuntu distributions of all versions.

 

 
#!/bin/bash

# Function to get OS version for CentOS/RHEL
get_centos_os_version() {
  os_version=$(cat /etc/redhat-release)
}

# Function to get OS version for Ubuntu
get_ubuntu_os_version() {
  os_version=$(lsb_release -ds)
}

# Function to get PHP version
get_php_version() {
  php_version=$(php -v | awk '/^PHP/ {print $2}')
}

# Function to get installed PHP extensions
get_php_extensions() {
  php_extensions=$(php -m)
}

# Function to get MySQL/MariaDB version
get_mysql_version() {
  mysql_version=$(mysql -V | awk '{print $5}')
}

# Function to get Apache version for CentOS/RHEL
get_centos_apache_version() {
  apache_version=$(httpd -v | awk '/^Server version/ {print $3}')
}

# Function to get Apache version for Ubuntu
get_ubuntu_apache_version() {
  apache_version=$(apache2 -v | awk '/^Server version/ {print $3}')
}

# Detect the OS type and call appropriate functions
if [ -f "/etc/redhat-release" ]; then
  get_centos_os_version
  get_php_version
  get_php_extensions
  get_mysql_version
  get_centos_apache_version
elif [ -f "/etc/lsb-release" ]; then
  get_ubuntu_os_version
  get_php_version
  get_php_extensions
  get_mysql_version
  get_ubuntu_apache_version
else
  echo "Unsupported OS. Exiting..."
  exit 1
fi

# Print the gathered information
echo "OS Version: $os_version"
echo "PHP Version: $php_version"
echo "Installed PHP Extensions: $php_extensions"
echo "MySQL/MariaDB Version: $mysql_version"
echo "Apache Version: $apache_version"