Apply Domain-Driven Design to microservices architecture using OpenFaas

Amir Movahedi
Dec 22, 2019 · 5 min read

In this Article you will learn about Telar Social Architecture using OpenFaaS and how it helps to boost your productivity, development Speed, flexibility, scalability and so on. We are not going deep in DDD and Microservices but how we used them in Telar Social in a nutshell.

What is microservice

It’s a system design style that break your system to small independent microservices.

Microservice advantages

  • Easier to build and maintain project.
  • Smaller and faster deployments.
  • High scalability.
  • Low impact on other services with isolation.
  • Freedom to choose technology.
  • Improve team productivity. and more advantages.

Domain Driven Design for Microservices

Domain-Driven Design (DDD) — a design approach where the business domain is carefully modeled in software and evolved over time, independently. It used to build systems that have a complex business domain.

Microservice Communication in Telar Social

  • Synchronous Front of each microservice is a Rest API. The client sends a request and waits for a response from the service. That’s independent of the client code execution that could be synchronous (thread is blocked) or asynchronous (thread isn’t blocked, and the response will reach a callback eventually). The important point here is that the protocol (HTTP/HTTPS) is synchronous and the client code can only continue its task when it receives the HTTP server response.
  • Asynchronous Message Queuing In this system, messages are persisted in a queue. One or more consumers can consume the messages in the queue, but a particular message can be consumed by a maximum of one consumer only. Once a consumer reads a message in the queue, it disappears from that queue. If there are no consumers available at the time the message is sent, it will be kept until a consumer is available that can process the message.
  • Asynchronous Publish subscribe (Enterprise Edition) In the publish-subscribe system, messages are persisted in a topic. Consumers can subscribe to one or more topics and consume all the messages in that topic. In the Publish-Subscribe system, message producers are called publishers and message consumers are called subscribers.
Microsoft Communication in a microservice architecture

Telar Social Microservice Architecture

In Telar Social following best practice architecture, Following this architecture:

  • We can have different team with different technologies, different programming language and base on different
  • We can config auto scaling for each microservice base on the metrics (like network traffic) to be specific for that microserice. By that we optimize resource usage and reduce the cost.
  • In the case if a microservice crashes, other microservice continue their job giving service to the clients.
  • Kubernetes do periodic checks on the health state of each microservice. If a microsevice fails consecutive health checks over an extended time period, Kubernetes initiates a repair process for that microservice.
  • Change and maintain a microservice without influencing on other microservices.
  • Each miroservice configuration is separated to different config file which is accessile via config directory from project root directory. Specially for Enterprice you can use different database for each microservice base on your business domain.

Community Edition Design on Kubernetes

  1. Client Send a synchronous request to API Gateway and waiting for the response from microservice.
  2. Client/Microservice Send an asynchronous request to API Gateway and pushing in the queue. In this method user do not wait for the response any more. After microservice is done with the job will call Action microservice(or other microservices) . Action microservice will send the appropriate action to UI dispatcher to update the user interface. (To learn more about Action Microservice read Flux Pattern for Server-Client interaction in Telar Social article)

Enterprise Edition Design on Kubernetes

  • Communication For Enterprise Edition, in addition to Community Edition communication, we provided Pub/Sub using Kafka. Microservices are subscribing to Kafka topicsand when a message received the function will be executed handling the message. In this pattern a message can be consumed with many functions at the same time.

Directory Structure

Core: Including core operations on Telar Social. We keep the src/core as the most stable layer that other layers use in common.

Controller : The Controller handle any incoming request from API Gateway. Controllers including functions called handler which handles incoming browser requests, retrieves necessary model data and returns appropriate responses.

Services: Do the data operations on your domain.

Web: Including Telar Social frontend using ReactJS.

root-directory
├── src
│ ├── core
│ │ ├── config
│ │ ├── data
│ │ │ ├── Client-DB
│ │ │ └── ...
│ │ ├── server
│ │ ├── utils
│ │ └── ...
│ ├── domain
│ │ ├── domain-name-1
│ │ ├── domain-name-2
│ │ │ ├── sub-domain-name-1
│ │ │ ├── sub-domain-name-2
│ │ │ └── ...
│ │ └── ...
│ ├── constants
│ ├── controllers
│ │ ├── domain-name-1
│ │ │ ├── handlers
│ │ │ ├── config
│ │ │ └── vendor
│ │ ├── domain-name-2
│ │ │ ├── sub-domain-name-1
│ │ │ │ ├── handlers
│ │ │ │ ├── config
│ │ │ │ └── vendor
│ │ │ ├── sub-domain-name-2
│ │ │ │ ├── handlers
│ │ │ │ ├── config
│ │ │ │ └── vendor
│ │ │ └── ...
│ │ └── ...
│ ├── models
│ │ ├── domain-name-1
│ │ ├── domain-name-2
│ │ │ ├── sub-domain-name-1
│ │ │ ├── sub-domain-name-2
│ │ │ └── ...
│ │ └── ...
│ ├── services
│ │ ├── domain-name-1
│ │ ├── domain-name-2
│ │ │ ├── sub-domain-name-1
│ │ │ ├── sub-domain-name-2
│ │ │ └── ...
│ │ └── ...
│ └── web
│ ├── ts-front-end
│ └── ts-ui
│── config
└── playground

Learn more about the project 🥧 🍰 🎂 🍮 🍭 🍬

👋 For more information please visit Telar Press or Red Gold team official website.

Red Gold

Build a smart society

Amir Movahedi

Written by

Love working on cloud infrastructure and decentralized network . Focusing on clean architecture, reusable code and cross platform. https://amir.red-gold.tech

Red Gold

Red Gold

Build a smart society

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade