Senior Software Engineer writing practical notes on architecture, Android, cloud, and software engineering craft.
NwHack 2022
Azure Communication Services (ACS) sponsored nwHack 2022 at The University of British Columbia. It was great to see the engagement from students to leverage open source API’s to solve daily problems. …
Past (2021 (365 - 8)) - Present (Today 😊) - Future (*)
At the beginning of year 2021, my professional goal was to write bogs as well as to work on designing a software system. …
Software System Design
I do not know how the perfect software architectures are build. It is possible that perfect software designs are myth. …
Android Sample Chat Application using Azure Communication Services and ChatKit
This post demonstrates the Android chat application leveraging Azure Communication Services and ChatKit.
Harnessing the Power of Less
Last week, I read an article “Harnessing the Power of Less” published in Special Times Edition “Secrets of Success”. The beautiful line “Stretching encourages adaptation and working with what you already have, rather than focusing on needing more” …
Kotlin map, foldRight & nested functions to implement redux middleware
Kotlin supports Higher order functions. In this blog, I will create a higher order function that will use map & fold right for execution. Before diving into higher order functions, let’s go through map & fold right. map is collective transform operation. var numbers = mutableListOf(1, 2, 3) numbers = numbers.map { it*2 }.toMutableList() // elements in numbers: 2,4,6 foldRight accept initial state, apply initial state to all elements and return final state. var numbers = mutableListOf(1, 2, 3) var result = numbers.foldRight(100, {a,b -> test(a,b)}) private fun test(a: Int, b: Any): Int { return a + b as Int } /* First execution: initial 100 a = 3 b = 100 Second Execution a = 2 b = 103 Third Execution a = 1 b = 105 final: result = 106 */ Let’s create a higher order function Middleware that takes an instance StringApp, has inner function next: Type and return Type. ...
Dagger, Injecting custom objects (Interface implementation)
It is very connivent to use any DI framework when all the objects required are available in application. For example, I have two classes Logger, Service and class Middleware is dependent on these classes. class Logger() class Service() //this class requires Logger & Service object class Middleware(private val logger:Logger. private val service:Service) // middleware object val middleware = Middleware(Logger(),Service()) Dagger can build objects of Logger and Service classes by indicating @Inject annotation to all three classes internal class Logger @Inject constructor() internal class Service @Inject constructor() //this class requires Logger & Service object internal class Middleware @Inject constructor(private val logger:Logger. private val service:Service) @Component interface MiddlewareComponent { fun buildComponent():Middleware } // middleware object val middleware = DaggerMiddlewareComponent.builder().build().buildComponent() If the project requirements are modified to get Logger with custom implementation, we can write @Module to support dependency injection. // now, Logger is interface interface Logger class Service @Inject constructor() class Middleware @Inject constructor(val logger: Logger, val service: Service) @Module class LoggerModule constructor(val logger: Logger) { @Provides fun providesLogger(): Logger { return logger } } @Component(modules = [LoggerModule::class]) interface MiddlewareComponent { fun buildComponent(): Middleware } //custom implementation class NullLogger : Logger //injecting logger module with interface implementation val middleware = DaggerMiddlewareComponent.builder().loggerModule(LoggerModule(NullLogger())).build().buildComponent()
Android/Java Dependency Injection Frameworks (Android Library & App Development)
Below are widely used Dependency Injection frameworks mostly by android & Java application projects. For Android application development, the suggested Framework by Google are Dagger and Hilt. These frameworks help to avoid writing boilerplate code. Guice Guice (pronounced ‘juice’) is a lightweight dependency injection framework for Java 6 and above, brought to you by Google. (github.com) With 10K stars this framework is mostly used by Java developers where Java is used for backend & Application development. For Android, this framework is not suggested as this framework use reflections to scan annotations from code. This requires significant CPU cycles and RAM thus slowdowns application launch. Reflection on the desktop/server JVM is very efficient, and even very large Guice applications don’t have performance problems related to Guice. Manage your app’s memory | Android Developers : Other dependency injection frameworks that use reflection tend to initialize processes by scanning your code for annotations. This process can require significantly more CPU cycles and RAM and can cause a noticeable lag when the app launches. ...
Distributed caching - Redis
Redis is in-memory data structure store. Redis has a really good documentation to learn and implement framework capabilities. My mentor at Job guided me to learn Redis. My primary focus is to understand how Redis helps for Distributed Caching. Distributed Caching Distributed Caching is cache shared by multiple servers. The miclsroservices or services can keep it’s own cache for data but distributed cache has many advantages as we can scale and manage cache at one place. The caches are used to save time to reduce cost to read database from database. The in memory(RAM cache) data is much more efficient to perform read operations as compared to SQL databases. Redis supports distributed caching by clusters. Twitter has redis instance for every user across data centers. When a tweet comes, the tweet is inserted into redis cache instance of every user who follows the tweet owner Real Time Delivery Twitter. Distributing caching helps twitter to deliver 300k tweets/sec. ...
MVC & MVVM Android Design Pattern (Android)
Recently, I developed an Android application. The application was developed focusing on simplicity. The application was small thus skipped writing unit tests. I know skipping the unit tests is not a good practice. In past, I was working on backend projects where tons of unit tests exists for API’s. I am new to application development and spent some time to learn about MVC and MVVM design patterns. For next project, the preference is MVVM. At end of this post I will share the reason to choose MVVM. The example code for this post is written for Android application. MVC (Model-View-Controller) Model: Model is data layer. Model call services or database to get data from external systems. View: View is user interface layer. Controller: Controller is triggered first. Controller has reference to Model as well as View. Controller get data from Model and send to View. ...