Is XML over sockets a good or bad mark?

I am working on a system that passes xml through sockets for a while. And I never understood what the real advantage of choosing xml over sockets instead of the user protocol is.

But I see many developers (especially initially web developers) setting up such an implementation (xml over socket).

I understand that this is more โ€œhuman readableโ€ (this is what I keep hearing).

But,

  • Xml contains a huge number of characters, which leads to huge messages when in fact the content is really small and simple.

  • The message size changes, so you need to ensure that you end your message with a specific character or string pattern.

  • When parsing xml

    there is more overhead

For all these reasons, I am still skeptical of considering XML over sockets for new systems, when I can configure my systems using a special protocol using fixed-size messages. Avoid sending huge messages, and performance affects xml parsing on client size.

Am I wrong to think so? What is โ€œbetterโ€ in terms of system architecture?

Hi

+4
source share
7 answers

Design decisions are about compromises. You have indicated that XML gives you readability and self-description. It also contains a description language (XSD), extremely portable, etc. Etc.

But these advantages have the disadvantages you are talking about. So let's figure it out one by one:

Verbosity

Yes, XML is verbose, being self-descriptive and text-based. This is really a problem if performance is a problem. It? What about positive trade-offs?

Note that a reasonable alternative here is JSON, which is also readable, but much more efficient.

Parameter Size

Yes, but it depends on the level of connection. If you do not have a permanent connection (for example, HTTP), or you use a protocol that provides it with its own "framing" (for example, AMQP or JMS), then this is not a problem - the transport layer will take care of this. If you plan to invent a new wheel, then the variable payload makes the protocol more complex. But the protocol (especially with all extreme cases) is quite complicated.

Service Data Analysis

This is directly related to verbosity.

+3
source

The main reason XML is traditionally used when transmitting data over a network is because it is extensible. It scales your application and turns it into a potential platform for other applications to build on yours, or allows other applications to integrate more easily with you, without solving a problem that has already been resolved.

In the end, this is what the developers paid for. Solve new problems. Do not create them.

Ryan Tomayko talked about this in his blog article about How I explained REST to my wife when he emphasized that using the standard means that individual systems around the world can be networked together to form massive, cohesive but individual systems.

When you use your own proprietary protocol, you basically limit your application to only communicating your own small world. Then, when it's time to glue it together with another system, much more integration is required at both ends.

With that said, JSON is starting to get a lot of traction as a replacement for XML. It is lighter, is understood by several platforms and is actually native to the Web language, JavaScript.

Any choice is good because you use something that all experienced developers will easily understand and that every system is capable of consuming.

+6
source

There is no "best" solution, all about your requirements. If you need very high performance, you should use some kind of custom binary protocol with small messages. However, this also has its drawbacks. The main advantage of XML is that it is a very standardized format that is easy to read from a wide range of platforms and applications. For example, using the cusom protocol, you will need to serialize and deserialize your messages. In addition, XML is much more extensible than a custom format.

So, to summarize, it really depends on the requirements of your system.

+4
source

Using a user protocol will not be a good idea, as it will require a lot of effort in development and testing, which is not necessary. In addition, it will be a concrete implementation, unless you put a lot of effort into developing it in a general way. With XML, the transport itself will not be associated with your application. Because XML is flexible and extensible, it allows you to change the structure and content without affecting your transport.

Although using XML has its own set of drawbacks, as you pointed out. It is true that this is due to excessive weight transfer. But alternatives like JSON would be a good idea to get around these issues.

+4
source

The fact that the protocol works on sockets is not directly related to the issue.

The reason many people choose to use XML for the presentation layer of their protocols is primarily because it avoids the effort and expense of defining and implementing your own presentation layer. Yes, if you need a different trade-off between message size, potential for change, cost of implementation, and other factors, then you can very well develop a protocol that is optimized for these requirements, better than XML. Or, given that many very good people were involved in the XML design, you can create something worse (usually because your long-term requirements are not what you think they were - for example, you could design something with excellent performance, but very little potential for change). But regardless of whether you are doing a good job or poorly performing your design, it will cost you more than using something like XML or JSON that already exists.

+3
source

Rethinking wheels is never a good idea. I would adhere to the standard HTTP protocol and use a compatible data exchange format such as XML or JSON. You will find many other tools and support if you use standard protocols instead of re-creating your own protocols. This is in terms of best practices. Of course, if you have very specific requirements, there may be good reasons for implementing something more customizable.

+2
source

As you explained, XML has its advantages and disadvantages. If you need alternatives to reduce network traffic, you can consider http://code.google.com/p/protobuf/ , which compresses data and has its own marshaling methods. And the other, which is well known in web technologies, is JSON.

Which is better from the point of view of system architecture: we need to determine whether this is integration with the Web or Enterprise System and others. It all depends on which system you are developing.

+2
source

Source: https://habr.com/ru/post/1413483/


All Articles