Which server to use for the mobile app. Mobile client server development

Which server to use for the mobile app.  Mobile client server development
Which server to use for the mobile app. Mobile client server development

488 Part IV. Ajax in examples

bots, and invokes the server, which will dynamically generate response data based on the submitted query string value. The first parameter of the LoaciXMLXSLTDoc() function is the URL of the PHP page that generates the XML document, concatenated with a query string formed by reference to the HTML Form O field values. The second parameter is the name of the © XSLT file used in the XML data transformation. The third parameter required by the LoadXMLXSLTDoc() function is the ID of the div element in which to place the search results. The identifier is the string name of the output element, not an object reference; in this case, the string "results" is used as the identifier.

In the next step, we use DOM methods to add an indicator image to the Web page. An image element is created © and the image source attribute is set to O. This created element is added to the results div element ©. Thus, when our function is called from the form's onsubmit event handler, an image file is placed on the page. In general, it is important for the user to create a visual feedback- a message or image, - indicating that processing is in progress. This prevents the user from repeatedly clicking on the handicap submit button thinking that nothing is happening (remember, the Ajax process is "invisible").

The last step is to call the LoadXMLXSLTDoc () ® function, which initiates the process of sending information to the server. The LoadXMLXSLTDoc() function described in Section 12.4 handles the call to the ContentLoader() object that requests documents from the server. By setting the output position as a parameter (rather than hard-coding the value in the LoadXMLXSLTDoc() function), we can reuse this function on one page without requiring for separation functionality adding multiple procedures or if statements. Therefore, we redirect the results of various search queries to different parts of the page. However, before we do all that, let's see how to create XML and XSLT documents on the server.

12.3. Application backend code: PHP

IN In this section, we will create a dynamic XML document using PHP - a popular open source scripting language source code(as you know, the Ajax framework is compatible with any server-side language or platform). The XML document is generated dynamically from the result set received in response to a client query against the database. In addition, we'll show you how to create a static XSLT document that resides on the server and is retrieved every time a dynamic file is requested. Both of these documents are returned to the client independently when the ContentLoader object is requested in two separate requests (Listing 12-7). The XSLT transforms our dynamic XML document on the client side and creates an HTML table that is displayed to the user.

Chapter 12 Live Search Using XSLT 489

12.3.1. Creating an XML Document

Since we are using XSLT, we need a structured XML document that is simple notation information so that the XSL file can perform the standard transformation. IN this project we'll create a dynamic XML file when the client requests a PHP file.

XML structure development

Before we start creating the XML file, we need to create a template for it. This pattern should reflect the structure of the data returned by the search. In the chosen task statement (phone book), we will return the company name, contact name, country, and phone number. Listing 12-3 shows a basic XML template that contains four fields.

Listing 12.3. Basic XML File

company name contact name country name phone number

The first element is phonebook. Next is an entry element containing sub-elements with all the details that are related to all contact numbers found in the request. If we have five results, there will be five entry elements in the XML document. The name of the company is displayed in the company element. In addition, we have added the name of the contact person, the name of the country and the phone number. We are not limited to the specified fields; Fields can be added or removed depending on what information you want to display.

If no results are found, instead of displaying a warning message, you can create an element that displays this information to the user. STO will make it easier for us to return the result to the user and will not require additional code in the client side of the application. The code in Listing 12-4 is pretty much the same as the code in Listing 12-3, but this time we enter text into the XML elements we want to show to the user to indicate that no results were found.

Listing 12.4. XML file with no results

no results

// O Displays "No R e s u l t s" instead of company name N/A

490 Part IV. Ajaxin examples

// © Remaining fields are replaced by "N/A"

N/A

N/A

With this code, we display a single line to the user telling the user that the requested information is missing. The company O descriptor displays information indicating that there are no results. Other descriptors 0 tell the user that there is no information. If we don't want to display the text "N/A" ("not available"), we can add instead non-breaking space, which will show the table cells. If we had not added any information at all, the cells in the table would not have appeared.

As you can see, the XML format has a very simple structure. If given XML file was static, it would be relatively easy for the user to add a new subscriber to the file. Since it is dynamically created, we need a loop that creates an XML document from the result set.

Creating a Dynamic XML Document

As always, we create an XML document on the server. In keeping with the policy of using different server languages ​​in the examples, the server code for this chapter is written in PHP. Recall once again that the Ajax framework can be created using any server-side language, and we will only describe the principle of implementing server-side code without going into details. So, Listing 12-5 shows the code for the server side of the application. The code takes a query string parameter and generates a lot of database query results. We then iterate through the set of results, creating an element in the XML file, as shown in Listing 12.4, for each phone number returned in response to the query.

Listing 12.5. phoneXML.php script: generating an XML document on the server

// About Declare MIME Type header("Content-type: text/xml"); echo("\n");

// © Connect to database

$db = mysql_connect("localhost", "ajax", "action"); rnysql_select_db("ajax",$db);

$result = mysql_query("SELECT *

FROM Contacts WHERE ContactName like "%". // © Fill out the request

$_GET["q"] ."%"",$db); ?>

// O Check results

if ($myrow = mysgl_fetch_array($result)) ( do (

// © Loop through the set of results

Chapter 12 Live Search with XSLT 491

001">

)while ($myrow - mysql_fetch_array($result)); )else(

phone book, or issue the message "No Results" 0.

12.3.2. Create an XSLT Document

Using XSLT, our XML file can be converted into a beautiful HTML table with a couple of lines of code. An XSLT document allows template matching if it is necessary to display data in any required format. Template matching uses a template structure to display data. At the same time, we pass through the nodes of the tree

492 Part IV. Ajax in examples

source using XSLT. An XSLT document takes a structured XML file and converts it into a format that is easy to view, update, and modify. In our case, the XSLT document is statically defined.

XSLT structure

An XSLT transformation contains rules for translating a source tree into a destination tree. The entire XSLT process is to match against a template structure. When the elements of the source tree match the given structure, the destination tree is created according to the document template.

The structure of the destination tree does not have to be related to the structure of the source tree. Therefore, the original XML file can be converted to any desired format. It is not necessary to use only a tabular view of the dataset.

An XSLT transformation is called a style sheet because it defines the styling of the resulting tree. The style sheet contains template rules, which are composed of two parts. The first part is the template structure against which the nodes of the source tree are compared. Having found a match, the XSLT processor uses the second part - a template containing descriptors for building the source tree.

Create an XSLT Document

Generating an XSLT transformation for a given project is relatively simple. Since we're going to get a table, no fancy pattern matching is required; we simply sequentially go through all the element nodes of the source tree. Below we will develop a template that generates an HTML table with four columns. The corresponding XSLT file for this project is shown in Listing 12-6.

i Listing 12.6. XSLT file

"ISO-8859-l"?>

// О Set XML version and encoding

// © Set the XSLT namespace"http://www.w3.org/1999/XSL/Transform">

// © Set template rules

// About Add a table element

// © Create a title bar

Chapter 12 Live Search Using XSLT 493

// 0 Sequentially go through the elements of the phone book

select="phonebook/entry"> // © Format the output

Company contact Country phone

When you create an XSLT transformation, you must specify the XML O encoding and version, and specify the XSLT © namespace. The namespace defines the rules and specifications that a document must conform to. Elements in the XML namespace are recognized in the source document but are not recognized in the result document. The xsl prefix is ​​used to define all of our elements in the XSLT namespace. Next, you can set up a template rule - look for a structure / © that matches the entire document.

Now we can start creating a table template that displays our results. We add a table descriptor O that maps an identifier to the table. This is followed by a table header row © containing the names of the columns that indicate to the user what information is contained in the table.

Sequentially passing through the set of nodes of the source tree, we get the remaining rows of the table. In this case, a for-each © loop is used, in the process of processing entries, issuing nodes located in phonebook/entry.

Since we are sequentially traversing the document tree, we need to choose column values. To select values ​​from nodes, the value-of to operator is used to extract the value of the XML element and add it to the output stream of the transformation. To set XML element, whose text we want to extract, use the select attribute with the element name. Once you've generated the XSLT file and created the code to dynamically generate the XML document, you can complete the JavaScript code and see how combining an XSLT transformation with a structured XML file produces an easy-to-browse table.

In the next step, we return to the client side again, retrieving the files we just created with the HTTP response.

Our company offers services for creating the server part of mobile business applications and client web services operating in high-load environments. When developing each project, we try to apply an individual approach so that the resulting product becomes the most optimal solution specific customer goals.

If you are using a complex application that stores and / or processes data on the server, then there is a Back-end behind it - software package, hosted on a web server and running on an application, which in this case is called Front-end. The application hosted on the server can run simultaneously with big amount customers, which imposes requirements on high speed and safety of its operation.

Often the server side of an application is written in PHP language, as the most popular for such solutions. To implement simple server tasks can be used standard systems, but for more specific ones, it is already required to develop your own solution or add-ons over standard systems.

Principles of developing a server for a mobile application

Our programmers work with technologies that allow us to implement a wide range of solutions for any, even very high workload and various areas. We also create separate server solutions for individual tasks.

Organizational control

Each project is created by a separate group of specialists responsible for all stages of development and delivery of the project on time.

Programming

Designing the server architecture is the most important step during which databases are created and the necessary algorithms are formed.

Testing

The software part should work without errors and failures. This is the responsibility of the testers who carry out the verification of the system.

Technical support

Our employees perform full-fledged technical support of programs, which allows you to quickly eliminate deficiencies and make updates.

Development Features

In order to competently develop the server part of the application, certain skills and knowledge of the programming language used on the server are required. As practice shows, client-server applications are created in PHP. He is the undisputed leader in this field. More than half of the sites in the world are written in PHP, it is convenient for development and support.

Framework

This software platform allows you to make the project more scalable and flexible. Nevertheless, the framework should be chosen as correctly as possible, therefore, a deep analysis of the working documentation of the project is required, which will subsequently help to develop a high-quality product.

There are other languages ​​used for back-end development. For example, server applications created in Delphi environment. Due to it, the program has improved debugging. Moreover, it is easier to develop unique programs, it provides visual creation. All this allows you to make a clear and convenient interface.

Java server applications are no less popular. They are easily complemented, easily executed on different platforms, and have a high level of security.

Another commonly used language. With it, server applications are created easily, quickly and at no extra cost.

Almost all modern companies have their own virtual offices. The website can be either a business card or a portal or online catalog with checkout options.

Business processes in this case are dependent on web servers, namely their ability to withstand attacks, hacking attempts and external negative impacts, as well as performance sufficient for many simultaneously received requests.

Stages of web service development

Creating applications for different market segments, we organize our work according to single principle– we break the whole process into separate steps, the progress and results of which are reported to customers. Thus, the server mobile application developed in a similar way.

1. Idea development

Up to 2 weeks

At this stage, the foundation is being created, giving an idea of ​​what will be laid down and in what direction it will develop.

2. Project evaluation

2-3 weeks

Our experts evaluate the time and cost of the work, then a preliminary proposal for development is drawn up.

3. Terms of reference and contract

Up to 2 weeks

After discussing with the customer all the nuances of the process and drawing up a detailed TOR, a contract is prepared and signed.

4. Interface development

2-3 weeks

Creating the interfaces needed when writing software modules, designers are engaged.

6. Testing

2-3 weeks

Comprehensive verification of received software solution produced by testers through a set of appropriate tools.

7. Completion of the project

Up to 2 weeks

Within the agreed timeframe, a ready-made, thoroughly tested web service is handed over to the customer.

our team

Through the analysis of commercial activities and the needs of our customers, we create real-world products that help solve a range of business problems. Usage modern technologies provides a wide range of possibilities for the implementation of server software, which guarantees the high performance of the corresponding mobile applications. Our team is represented by:

Project Managers

These employees interact with both clients and developers, providing communication between them. They monitor the implementation of both the already planned actions and the necessary improvements.

Designers

In their work, our specialists take into account the requirements for building interfaces for operating iOS systems and Android, so the released applications work correctly on different devices.

Developers

In order to optimize the performance of mobile applications, programmers analyze them system requirements and create specialized server software.

Testers

Thorough testing is a guarantee of the quality of the finished product and a guarantee of the security of stored and processed data. These specialists use different tools and an effective methodology.

What services do we create

Being embedded in the site software or independent program, a web service is used to perform tasks related to advertising, analytics, planning and business promotion. In this regard, it is necessary to decide what type of resource will be the best solution.

Information projects

Designed to accommodate diverse content.

Thematic sites

Almost all of their pages are devoted to one topic. The demand for them is still quite high.

news sites

They inform about various news within the framework of one or more topics, reflecting the main areas of life.

Blogs

The level of popularity of these resources is constantly growing. Like news sites, they convey this or that information to the Internet community, but in this case, the authors express their personal opinion.

Social projects

These include specialized social networks, communities, forums, etc.

Forums

Created to discuss various news, products / services, etc. They can be both narrowly focused and diverse.

Social media

These resources have a multi-million audience. Their main task is to provide Internet users with the opportunity to communicate online via text / voice messages and video communications.

Various web services

Widespread today, they are divided into several types.

Catalogs

Postal services

Provide users with all the features and benefits of e-mail, including viewing, sending, editing letters and documents, etc.

Search engines

Used to search for sites and various information for certain requests.

Notice boards

These are web resources where network users place their advertisements for the sale and purchase of services within various topics.

Hosting sites

Designed for temporary storage of files. Some of them provide an opportunity to get acquainted with the data before downloading.

FAQ

Below we offer answers to questions that are often asked to our specialists. If you do not find the information you are looking for here, please post your question here. form and we will definitely answer it.

How long can it take to create an application and a web server?

On average, this work lasts from 9 to 20 weeks. It all depends on the complexity of the task being implemented.

Offline in the past, being online today is a must. At least for the modern business world. Presentations of products and services of brands, online ordering and delivery, maintenance of a customer base, communication with customers, and much more - all this is simply impossible without an Internet presence. If you need an application, you must have both a Front-end (the web interface) and a Back-End (the server side of your application). And if you want to be able to edit the content of your application without the participation of developers, you need a good admin panel.

While the front-end in mobile applications is built using technologies such as X-Code and Java, the back-end, where the database and all application logic will be stored, requires professional knowledge of the server-side programming language. A good example is PHP, which is arguably the most popular programming language that is used to develop almost any back-end. This is the undisputed leader.

There are many applications for PHP: static and dynamic websites + custom content management systems, social media, specialized CRM systems, software for e-commerce, and more. Of course, there are free or cheap server parts and control panels. However, in many cases they do not provide the necessary level of convenience, customization and upgradeability.

Our programmers work with technologies that allow us to implement a wide range of solutions for various business goals, needs and requirements. We analyze the system requirements for each project individually and apply various specialized server software for optimal performance of your mobile application.

If you're looking for a team that can lead you to the most intelligent and cost-effective solution for building an application from scratch or restoring an existing one for a perfect user experience, look no further. Appsmob is ready to help you find the best solution for you.

BACKUPS

Why backups are needed on a mobile platform

Experts know how unreliable 1C mobile applications are sometimes: errors can occur at any time, due to which user bases simply collapse. At the same time, we are faced with the unreliability of the devices themselves: they can be broken, lost, stolen, and users want to keep their data. And up to version 8.3.9 we didn't have a platform backup mechanism.

Since users didn't have a "save a copy" button before, the developers of the Boss app had to make backups themselves. How did we do it?

We save the database data in the form of XML.

It is advisable to offer the user several options for storing copies - first of all, it is convenient for customers, they can choose the best option for themselves: upload to the cloud, send it to their mail, save it on the device.

Thus, the developers additionally insure themselves. If something went wrong, and the mechanism for creating copies on Google Drive or Yandex Drive suddenly broke down, you can always tell the user that in this moment the developer deals with the error, but for now he can save the data alternative way. And users are satisfied because they can be calm about their data.

Necessarily focus on cloud services, because if the device is lost or broken, and the user saved a copy on the same device, then the data will be lost.

Also we be sure to remind the user of the need to create backups.

How to save copies if the configuration changes?

When we talk about a mass solution, about an application that is constantly changing, developing and improving, we must take into account the behavior of customers. The user may want to restore a backup saved in old version application, where there were no details. And then the task arises: to read the data, then fill in the data according to the update logic from the old version of the application. How to do it? In addition to the data, save the data structure itself, so that later you know how to read them.

There are several options for storing this data structure, including storing it in the configuration itself. That is, with the release of each new version, save the metadata structure previous version to layout in config.

Do not forget that in a mobile application, the configuration should not grow just like that, we must value the place in it, we must make it as compact as possible. But the application is developing, and there will be many such layouts, and over time there will be more and more of them.

Therefore, in the case of a mobile application, another way is preferable - save the metadata structure directly in the data file. At the output, we get such a file, where at first we store some auxiliary data - the configuration version, configuration scheme, sequence boundaries, and after that we write the user data themselves into XML format. Moreover, in the "Auxiliary data" section of the file, you can also store other important data that for some reason could not be written to XML.

We take the data schema that was saved to the file, and based on it we build the XDTO package for reading the file. We create a similar object in the database, fill it in, perform completion processing when updating, and save the finished object to the database.

Below in the picture you can see a hint on how to beautifully write the XDTO model of these configurations. The company that released the Boss application experimented with this, found several ways, but settled on just this option for writing the metadata schema. When the data file itself is opened, you can see the usual structured XML, readable, which lists all the metadata of the application.

// Write configuration schema XDTO Model = XDTO Factory.XDTO Model Export("http://v8.1c.ru/8.1/data/enterprise/current-config"); FactoryXDTO.WriteXML(FileUpload, ModelXDTO); // Read configuration schema ModelXDTO = FactoryXDTO.ReadXML(ReadingXML, FactoryXDTO.Type("http://v8.1c.ru/8.1/xdto","Model")); Unload Factory = New XDTO Factory(XDTO Model);

To protect the user, it is necessary to ask him again if he needs to restore the backup. Maybe he was just experimenting and clicking buttons on everything in the application :) And now his current data may be lost. Therefore, when performing potentially "dangerous" actions, we always clarify whether he really wants this, and how this should happen. The user must be aware of his actions.

There must be a mechanism for creating backups when we talk about an offline solution, when the user has all the data stored exclusively on a mobile device: the user can lose his device, and then the data will be lost. And it would seem that if the application does not work offline, but is connected to a central server, then the user should not have such a problem, because if the device is lost, he will connect to the server, receive all his data from the server again, and everything will be ok.

However, users do not always use backups in the way we expect from them :) They very often use them in order to simply “roll back” data back. This is really a very strange behavior, but mobile application users are too lazy to figure out where they could make a mistake when entering data, and they simply roll back the data and re-start the data for the current day. After analyzing the statistics of working with the Boss application, we realized that this is a normal practice and such user behavior is more common than we could have imagined.

And if you use synchronization with other devices, then you must process this. There are several solutions here:

  • break the connection with the server, specifying that the data on it will remain as it was, and the copy will be restored only on the user's device;
  • it is better for the user to let him restore a copy on all devices at once, having previously prescribed such mechanisms.

There is one more point here. Until now, we saved backups ourselves, controlled the entire process, caught the user’s actions right in the code when he clicked the “save a copy” button. All this can be processed later. In platform 8.3.9, it became possible to save backups using the platform's tools. And the user does it without our knowledge. If synchronization with a central database is used, then such a scenario must be processed. We must somehow find out on our server that the user has restored a previously saved copy and must give him some kind of decision. We can't afford to let the data get out of sync.

EXCHANGE

When we talk about a private solution on a mobile platform, we usually have a customer who, for example, wants to use mobile platform for their sales agents, and for them to exchange data with a central database. Everything is simple here: one database, several devices, you raise the server, set up communication with it. So the problem of exchange between devices is solved easily.

But if we are talking about a mass application, where there are many databases, each of which has a lot of users, the situation becomes more complicated. Users have downloaded the app from the market and they want to sync with each other. For example, a husband has downloaded a personal finance app and now wants his wife to connect too so they can work together on the same app. There are many users, the application is developing, growing, and there is a need for a large, very large number of databases. How to organize all this? Users will not personally contact developers to create a separate database for them and enable synchronization. They want to push a button and make everything work right away. At the same moment.

How to proceed? This is where the data separation mechanism comes to the rescue. It allows you to organize a single database, where there is one common configuration, but at the same time, an unlimited number of user databases are stored within one common database.

The best part is that you can add users dynamically, programmatically, without our participation. In reality, users simply click on the “register on the server” button, and everything happens by itself: a personal database is created for him on the server, and he can immediately start working in it.

How to do it? The first and easiest solution is to write your own server base with this mechanism. When our company started to make the Boss application and exchanges in it, we did just that in the first version: we wrote a server database with a data sharing mechanism. Everything worked, especially since there was nothing complicated - the base separator is a common attribute.

But then we realized that we were reinventing the wheel :) In fact, there are already turnkey solution, and it already takes into account moments that we have not even thought about. This is 1C: Fresh.

The scalability of the service is thought out here: what to do when there is a lot of data and databases, how to grow with it all. There's a moment here about creating backups data areas: that is, we do not just backup one common database, we make copies of a specific user. Moreover, the mechanism there is such that copies are made only when they are really needed. If the user has not logged into the database for a week, then we do not make copies for him, because nothing has changed there. Another feature of Fresh is that the service has a mechanism to reduce the load on the server, and this is very important when you have a lot of databases.

In general, Fresh is something new and interesting for us. Slowly we are trying to figure it out, but for the most part we are just happy with his work.

Data transfer. How to implement it for sharing between devices

The platform provides two mechanisms - SOAP and http services. There are nuances here on how to access these services when the data sharing mechanism is enabled. In particular, you need to add parameters that indicate the specific number of the realm you are accessing, because the platform cannot determine which database to access based on the username. In addition, the same user can work with several databases within a single database (see picture).

In terms of services, the Boss app implements instant sharing: one user enters data, and the other receives it. Mobile application users are used to the fact that everything happens instantly, so we thought about how better service to use - SOAP or http. Connection speed played a key role. In http, the connection speed is much higher, and when connecting via SOAP, we get a service description that is heavy and takes a long time to load. The platform has a way to store a description of the service, but because of the parameters we add dynamically, we can't use WS links. In addition, accessing http services is more convenient and flexible, in our experience.

So, our goal is to implement real-time exchange. That is, we try not to make it so that the user has to go somewhere, click on some button, think about how up-to-date his data is, whether he should update it ... Users should always have up-to-date data. They are so used to working in messengers - one sent the data, the other immediately received it. Everything happens instantly. The same applies to applications related to business: one seller has issued a sale, the other should immediately see the current situation, without taking any action.

Therefore, the Boss application uses background jobs for exchanges. After each write of data to the database, it runs background job, which initiates the exchange. The first part is to send the data to the server. The other devices then need to know that there is new data. For this we use PUSH notifications. This scheme is already working and it works fast enough.

But we wanted even faster, because we work in real time and we usually have little data. We have small XML, but at the same time we send a message with this data from the first device to the server, the server sends PUSH to another device, and then the second device, after receiving PUSH, initiates the exchange on its part, accesses the server and requests data, receives this data and then sends a response that the data has been received. This is a long time, but there was very little data itself.

We thought about how this process can be accelerated.

To do this, we figured out what PUSH contains, how it can still be used. It turned out that PUSH contains fields such as data and text. The documentation for iOS and Android indicates the limits on the size of PUSH messages, but this seemed to us not enough and we wanted to figure it out by ourselves. And we checked that for iOS the sum of allowed characters is 981 characters, and for Android it is 3832 characters. In the latter case, it is quite possible to use the restriction; one or several base objects can be pushed into such a volume. And then the company's developers changed the scheme a bit. When there is not much data, we send it from one device, receive it on the server, pack it in PUSH and send it directly to another device. The scheme has become shorter, and the exchange has become even faster :)

An important point of using PUSH is that it does not annoy users.

It is very easy to get rid of this situation: just do not send a lot of PUSH messages to the user :) If he is currently working in the application, you can send a lot of messages. When the platform is running, the user does not see PUSH, everything happens automatically for him. But when the application is closed, the client has a lot of unread messages. Therefore, in no case should you send the next PUSH until a response is received from the device that the application is running, active and the previous PUSH has already been processed.

Another nuance of the exchange is work via the web. We need to use asynchrony as much as possible. You can't work as usual - write code - call a function - wait for it to execute - get a response - and everything is ok. If you are working on the web, you will still encounter certain limitations, such as unstable internet, triggering timeouts when performing long-running operations. Therefore, it is necessary to think over the architecture in advance.

Let's look at the example of device registration, what happens in the application when the user wants to register. He keeps records for a while, he entered a lot of data, but then he wants the seller to also work with this database. The user clicks on the "register" button. At first, everything was very simple: they took his data, recorded it on the server, and, please, you can work and connect users. But then we ran into a situation where for some users the databases on the device had already grown greatly by the time of registration. And this scheme no longer worked, because. while the entire database was being recorded on the server, the connection timeout was triggered or the Internet was simply interrupted. Therefore, we have replaced one synchronous call with many short ones. Data is now shared rather than being transferred all at once. We do not wait in any case while the server will process and write data. We sent the data, received a response that the data was received, closed the connection. Periodically, it is necessary to poll the server, what is happening there and how, and in the meantime, a background task is running on the server, which writes the received data. This makes a lot of server calls, but we have a guarantee that everything will go well. And neither timeouts nor Internet instability will prevent you from uploading all the data to the server.

UPDATES

Sharing between devices with different app versions

Since we are talking about a mass application that is released to the markets, it is necessary to take into account some features of the update and data exchange process.

If you released an application for one enterprise and decided to update it, then usually you just give a command that all employees unanimously install the new application. With users who downloaded the application from the market, this cannot be done. You can't tell them what to do at all. For example, they work in the application and do not want to update it now or ever. They do not have auto-update, so it is quite common for several devices to be connected to the central database, and all of them with different versions. Another reason for this phenomenon is the publication time in the markets: it is different for iOS and Android. We often implement key things, such as fixing critical errors, and don't want to wait until iOS checks two weeks new version, we want to at least only for Android, but release an update right now.

We have no right to command users. If they want, they update, and if not, they do nothing. The picture shows the ratio of installations of the Boss app by versions in GooglePlay, as well as statistics from our server - the real ratio of app versions that are installed on devices that have exchanged data with the server over the past week. Here is a set to work with. This different versions and various metadata. And we need to organize a normal exchange at the same time :)

Developers face the following tasks:

  • It all needs to work. Users shouldn't feel bad about forgetting to update. They shouldn't notice it at all. Updated - it became better, well, good.
  • We must ensure the safety of the data. For example, one user has a directory and a new attribute, while another does not yet. Moreover, if a user who does not have new details changes something on his device, then data on other devices should not be lost.
  • It is necessary to ensure that the data is updated when we switch to a new version. When the user decides that he is ready to upgrade, he should automatically have all the new information that he did not have just because he had the old version.

How did we do it?

1. We use 2 exchange plans on the server. The first is for sharing between devices, and the second is for updates. For example, we sent a directory to the user, but it does not have units of measure, that is, incomplete data. We must remember this. And when it is updated, we must send it all the information that it did not have. For this, a second exchange plan is needed.

2. To write and read objects, we use the same mechanism that is used for backups, that is, we save the metadata version. In this case, we are working with the server, and we can afford to add anything we want directly to the configuration, so we simply add metadata schemes to the configuration in the form of layouts as the application develops.

How to monitor massive errors in the exchange and on the server

First, you need to control the availability of the server itself. With servers it happens - they fall. We did not invent anything special to monitor, but simply found a bot in a telegram that screams if something is wrong. He checks the server's performance every minute, and if suddenly the server is unavailable, he starts screaming, the admins see this and raise the server.

We also collect an error log from the log. Also nothing supernatural - just every three hours we collect an error log, send them to the mail, periodically review them. This helps to see common problems and some exceptional situations. It is not difficult to view mail, track and quickly fix errors. But this allows you to quickly identify and solve problems that can grow with the growth of databases.

More important point- be sure to give the user the opportunity to "complain". This improves our status in their eyes and saves us. There are users, as we call them, "hysterics" who, at the slightest mistake, start sending us a bunch of messages by mail that nothing works, the database does not load, everything is terribly bad. But sometimes they really save us, because sometimes they find bugs that the rest have not yet miraculously discovered, serious bugs.

The user should not be scared. No scary messages, nothing else. They need to explain everything beautifully and offer to complain. And we promise to solve everything. Then the users are satisfied, because they see that they are taken care of, and immediately believe that they will be helped :)

This article was written following the results of the report read at the INFOSTART EVENT 2016 DEVELOPER conference. More articles can be read.

In 2020, we invite everyone to take part in 7 regional meetups, as well as the anniversary INFOSTART EVENT 2020 in Moscow.

The reverse side of mobile clients is the server.

Additional requirements depend on the specifics of the application:
server scalability - for SaaS, social applications, where ideally a large flow of visitors is expected, this condition is mandatory. For business applications where there are restrictions on the number of users or the number is predicted, given property not required;
interactivity: a number of applications need to be provided with a notification mechanism - to inform the application (user) about the occurrence of certain events, send a message to the user. For example, an exchange system or an automatic taxi dispatcher should have this property.
open API: it is assumed that third-party developers can use the functionality of the system through a documented protocol. After all, the client can be both a mobile and an external server application.
other requirements...

Team
The composition of the project team for system development would ideally be as follows:
project manager: manages, controls the project, interacts directly with the customer;
server application developer: develops business logic server, database, network protocol;
admin app developer: develops web application, user interface to configure and manage the server application;
Android client application developer;
iOS client application developer;
client application developer for...
tester: tests the admin application and client applications.

An attentive reader will notice that if you write a server application with a graphical interface, for example, in HTML5, you can save money. In this case, the development of client applications is not required - the user interface is provided by the browser. This article does not consider such a case, in question about developing native applications for mobile devices.

I had a chance to work in a team with a full complement, but be realistic - not always human resources and budget allow you to assemble such a team. And sometimes the roles have to be combined: project manager + server application developer, client application developer + tester.

Technologies, tools, libraries
To develop a mobile client server, I usually use the following stack of “free” technologies:
Apache Tomcat is a servlet container;
MySQL - DBMS;
Subversion is a version control system;
Maven - a framework for automating the assembly of projects;
JUnit - will provide ;
Apache Log4j - logging library;
Jenkins is a continuous integration system;
Hibernate - ORM (settings, configuration in properties, xml files and annotations)
hibernate-generic-dao - DAO implementation from Google, implements the main methods for working with database data, simplifies the implementation of filtering and sorting in methods;
- implementation of authentication and authorization (security), a container of services and beans (configuration in xml files and annotations), we also use it when creating tests.

Depending on the specifics of the system and the requirements for it, I use one of 2 options for implementing the data exchange protocol.
When cross-platform, speed, simplicity, efficiency, scalability, open API are required, then I take Jersey - the implementation of REST Web services (RESTful web services). This library allows you to use data serialization in JSON or/and XML format. REST configuration is maintained through annotations. For the exchange with mobile devices, the JSON format was taken due to the fact that it has a simpler implementation on the client side (for this reason we do not use “classic” Web services), a smaller amount of traffic is generated. Jersey allows you to tune in to the most appropriate "kind" of JSON.
Otherwise, if you need cross-platform, high performance, simplicity, efficiency, interactivity, then I take
Apache MINA is a framework for creating network applications,
Google protobuf is a structured data encoding and decoding library. The data structure is defined header files*.proto, the compiler generates Java classes from them (it is also possible to generate them for other programming languages: C++, Objective-C, etc., which provides the cross-platform property);
java.util.concurrent - use the standard package.
This option can be scaled, but it needs to be planned at the design stage at the architecture level, taking into account the business logic.

Consider a hypothetical task using the example of choosing technologies for a real SaaS service - “Auknem Services Auction”, which allows people to place an order for the performance of the required services or works, and organizations, in turn, leave their offers for them. We take all the basic requirements by default. In view of the fact that registration in this system is free and free, it is definitely necessary to add scalability to them. What about interactivity? It would be great to inform contractors (performers) about the creation of new orders, and inform customers about the proposals received at the same moment in the application, and not just by e-mail. Based on this, we will take Apache MINA, Google protobuf for implementation. We look at the following property - open API. The service is public, so let's assume that external developers may be interested in integrating with it. Wait! Not so simple. The Apache MINA-based protocol is quite implementation-dependent, and integration without knowing the nuances is by no means transparent. In such a situation, you will have to weigh which factor is more important and make a choice.

Conclusion
It would be interesting for me to know what technologies, libraries you used when developing a mobile device server or similar systems? Everything changes, nothing lasts forever, at every level there are alternatives with their own advantages and disadvantages: MySQL -