Tools for better client-server communication

Prasanth Perumal
3 min readFeb 26, 2020
Photo by Brett Sayles from Pexels

Before I start I am not an architect nor a developer who works on server components; instead, I am a mobile client developer and this article will be mostly on the changes that can be done to efficiently improve the client-server communication for applications from a client-side developer perspective.

ETag validation

Etag validation can be done using HTTP headers or our own implementation, The server sends a hash which is based either on the result data or the database status to the client. the client, in turn, caches the response along with the Etag. when the user requests the same data again the client sends the ETag along with the request to the server which validates the ETag and if in case it matches the current data hash, the server will not send the data and instead would throw a status code as 304 (Not Modified). The client will provide the user with the data which is already in the cache.

Certain points on ETag

  • There is no single method on generating ETag, its completely up to the developer’s interest.
  • The client can send the ETag during updating the data so that the server can validate the previous data hash with the one which was sent.
  • To reduce computation time the server can generate the hash and save it when there is a write process.

Client Load Balancing

mostly all systems contain server load balancers for directing traffic into either of their servers. But huge traffic can affect them hence use of client-side load balancing is an option.

  • The client can choose between a list of servers by either round-robin method or through any specific algorithm
  • Clients can form a network of load balancers for microservices.
  • HATEOAS: Hypermedia as the Engine of Application State can also be used to switch servers at runtime

Use Rest Api like a Pro

most of the services that are available in the market do not utilize the full potential of the Rest Apis. Things like

  • following a single URL with a complete set of CRUD operations will help us with caching properly
  • Proper response codes can be implemented with messages ex: status 202 for long batch processes which can contain a monitor
  • Versioning of API is a must and the old clients must have an option to connect to old API.
  • As discussed before the include and exclude keys for every API so that the client downloads only the required info.
  • You can go ahead and minimize, compress the data sent and received. Eg: GZip of text

Optimizing Image download and rendering

We already know things like lazy loading and caching of images. but few techniques can be used like

  • reducing/increasing the size of each image uploaded according to the display resolution, network speed, device capability.
  • Pre fetch images in the background
  • vector images can be shown and for trivial images, we can use custom fonts. Image sprites are a good way to club multiple images.
  • avoiding server-side picture editing

--

--