Designing a Cache System

Load balancing helps us scale horizontally across an ever-increasing number of servers, but caching will enable us to make vastly better use of the resources we already have. Caches can exist at all levels in architecture. A cache is like short-term memory which has a limited amount of space. The cache is typically faster than the original data source.

Screen Shot 2018-06-21 at 1.45.54 PM.png
A simple global Caching System

Let’s talk about different approaches first.

Continue reading “Designing a Cache System”


Microservices vs Monolithic Applications

A developing a server-side enterprise application. You must think of different clients:

  • Mobile devices and its browsers.
  • Native mobile applications.
  • Desktop devices and its browsers.
  • Exposing your APIs to 3rd parties.
  • Integrating with other applications.
  • Executing business logic, accessing a database or exchanging messages with different systems.
  • Returning a response.
  • Figuring out technology stacks.
  • Keeping things in your mind such as CAP theorem.
  • many more depends on the complexity!

It is very hard to define an architecture that supports as a set of loosely coupled, collaborating services using the Monolithic approach. Let’s imagine that you are building an e-commerce application that takes orders from customers, verifies inventory, and ships them. The application consists of several components including the StoreFrontUI, which implements the user interface, along with some backend services for checking credit, maintaining inventory and shipping orders. The application consists of a set of services.

Continue reading “Microservices vs Monolithic Applications”

RESTful API Best Practices

This post covers best practices for building HTTP and RESTful APIs. Let’s start with the terms that we will use mostly:

  • The resource is a information that can be a singleton or a collection. E.g. /companies, /company and /employees are resources. Collections are set of resources, e.g. /companies collection resource is the collection of /company resource. /Company resource is a singleton resource. A resource may contain sub-collections such as /companies/{company_id}/departments and it can be followed by a singleton resource, e.g. /companies/{company_id}/departments/{department_id}.
  • Operations such as patch, put, update, delete, and post can be performed on these resources.
  • URL (Uniform Resource Locator) is a path.

Continue reading “RESTful API Best Practices”

Simulated Annealing

Simulated Annealing (SA) is a probabilistic technique used for finding an approximate solution to an optimization problem. To find the optimal solution when the search space is large and we search through an enormous number of possible solutions the task can be incredibly difficult, often impossible. Even with today’s modern computing power, there are still often too many possible solutions to consider. Therefore, we often settle for something that’s close enough to optimal solution when we may be not able to find the optimal solution within a certain time.

Continue reading “Simulated Annealing”

Introduction Machine Learning: K-nearest neighbors and Perceptron Learning Algorithm

Machine learning is a subfield of computer science where computers have the ability to learn without being explicitly programmed. List of the machine learning task:

  • Supervised: Approximation where the all data is labeled and the algorithms learn to predict the output from the input data (training, cross validation and testing sets). We have two types of supervised problems:
    • Regression: When the output variable is a real value, such as “dollars” or “age”.
    • Classification: When the output variable is a category, such as “cat” or “dog” or “Tumor benign” and “Tumor malignant”.

screen-shot-2017-03-05-at-2-08-54-pmRegression vs Classification

  • Unsupervised: Description where the all data is unlabeled and the algorithms learn to inherent structure from the input data.
    • Clustering: A clustering problem is where you want to discover the inherent groupings in the data, such as grouping customers by purchasing behavior.
    • Association: An association rule learning problem is where you want to discover rules that describe large portions of your data, such as people that buy X also tend to buy Y.

Continue reading “Introduction Machine Learning: K-nearest neighbors and Perceptron Learning Algorithm”

Summary of AlphaGo article: Mastering the game of Go with deep neural networks and tree search

Lately, I have been working on artificial intelligence. I have read the article of “Mastering the Game of Go with Deep Neural Networks and Tree Search Research” introduces how to combine the best of deep neural networks and search algorithms to achieve what was thought the impossible.

The game of Go has long been viewed as the most challenging of classic games for artificial intelligence because of its enormous search space and the difficulty of evaluating board positions and moves.

Continue reading “Summary of AlphaGo article: Mastering the game of Go with deep neural networks and tree search”

Best Practices of Java Singleton Design Pattern

Singleton Pattern

We have different approaches but all of them have following common concepts to implement Singleton pattern:

  • Private constructor which restricts instantiation of the class from other classes.
  • Private static variable of the same class that is the only instance of the class.
  • Public static method that returns the instance of the class, this is the global access point for outer world to get the instance of the singleton class.

Where do you use the Singleton pattern?

Most of the scenarios, Singleton classes are created for resources such as File System, Database connections etc…

Continue reading “Best Practices of Java Singleton Design Pattern”