Create a fail-safe soft real-time web application using Erlang / OTP

I would like to create a fault-tolerant soft real-time web application for a pizza delivery store. This should help the pizza store to receive phone calls from customers, place them as orders in the system (via the CRM web client) and help dispatchers assign delivery drivers to orders.

These goals are not unusual, but I would like to make the service available 24/7, i.e. make it fault tolerant. Moreover, I would like it to work very fast and be very responsive.

Below is a very simple view of the architecture for such an application.

pizza delivery shop orders system

The problem is that I do not know how to use all the features of Erlang / OTP to make the application very responsive and fault tolerant.

Here are my questions:

  • What system elements should be replicated for fault tolerance and how to do it? I know that I can store the status of each car (coordinates, assigned orders, etc.) in the replicated Mnesia database. Is this the right way?
  • Which data storage services should be standard based on SQL (for example, based on boss_db ), and this should be done on Mnesia to provide a very fast response? Can I use a regular SQL database to store customer records and history in such a fault-tolerant and highly sensitive application?
  • Should I try to store all the data for all services (clients, vehicle status, etc.) in RAM so that the application is very responsive?
  • Do I have to store permanent vehicle data (id, capacity, etc.) in a regular SQL database and store real-time data (coordinates, assigned orders, orders in the trunk, etc.) in the Mnesia database, to make the application more responsive?
+7
source share
2 answers

First of all, this is a big question, but I will try to break it. Let's look at the facts first. This is a web service. This means that we have these layers: Web Server , Middle ware application , and then Data Storage . In most highly accessible applications, the storage tier should have redundancy through replication and load management through Distribution . In most real-world applications, you do not need to store anything in RAM if the application is really not in real time, such as Multi-player Game Server or A telecom Switch . So, your application, in this case, really does not need RAM (maybe some kind of caching here and there, as we will see.)

Now this type of application includes various types of data, information that cannot have the same form at any given time, so using RDMS will make you organize everything the same way. My suggestion is that you will learn to use any document oriented database , a NoSQL DB or key-value system , because they are well-modeled for real complexities. More information about any kind of storage can be found in this pdf . I suggest you use the Couch core server , according to which your data will simply be JSON documents , schemaless and can grow as your application grows. It comes with distribution and replication, just like any application has ever needed. You can add servers or delete servers at runtime, and the whole system will simply rebalance itself. It also comes with memcached built-in for caching, so for the IN-Memory part that you mentioned, caching will do everything for you.

After the Warehouse, let's talk about the middle dishes. I want to talk about the web server as part of a medium product. You will need a very stable web server, depending on the load, and for the fact that you want to use Erlang, I suggest the yaws web server and learn how to do RESTFUL services using appmods . Using Proxies sunch as a Nginx infront of a web server cluster can help with load management. At least there are several ways to balance the load on web servers. After that, you will need an OTP application. An OTP application does not have to have gen_servers . But, as you will find out, you will find, indeed, where you need parallelization or where you need serial code. However, he worries that you want to use something that you have not yet mastered. please follow this web book and this Orielly book to help you all about Erlang. You might find a useful opportunity to try out the Chicago Boss and Mochiweb or Misultin Http server Misultin .

Another thing that I should mention in this is that you need to master your data structures and have an effective way to work with them. Poor selection of data structures can cause problems. Test and check everything at every step. Use records wherever possible, and check memory consumption at every step. There is only a lot to say about this issue, but hopefully others are also going to post their opinions.

+8
source

hack this game: https://github.com/synrc/games all questions in real time, low latency, pub / sub, database, architecture, written as the most modern software. I suggest using gen_fsm to control the state in your application, as is done in okay supervisors. riak integrates with kvs lib, which also has good support for social updates. n2o chose the cowboy server, in my opinion, the best server around. http://www.ostinelli.net/a-comparison-between-misultin-mochiweb-cowboy-nodejs-and-tornadoweb/

+2
source

All Articles