Μετάβαση στο κύριο περιεχόμενο

The reality and the future of software engineering

State Management in Stateless Web Applications: Basics

The proliferation of REST and statelessness in Web Application and Web API design, state management often becomes a matter of misunderstandings and conflict in development teams. Programmers of back-end systems may be used to assume that session-related state is preserved server side and may be referred to as needed by the application code. However, stateful implementations may suffer from performance and scalability limitations, making thus the stateless approach a viable alternative, especially when high-load Web-based systems are considered.


How to pass data between requests in state-less / session-less Web applications

The problem here is that there are cases in state-less Web applications where data from an interaction may be required in subsequent interactions to be processed by the server, even though they are not stored in the server in some form. In this case, you will have to let the Web client provide these data as context (or state) of subsequent interactions.
Specifically, say for example that upon a form submission (Req1) you need to redirect the client (Resp1 (302) - Req2 -Resp2 (200)) to a second page/form where she should fill certain further information and submit (Req3). However, certain information submitted during Req1, or computed by the server as a result of Req1, need to be processed along with the information provided during Req3 so that the server can apply its processing logic. In this case, there are two basic options you can follow:

  1. Cookies as context: I will not go into the theoretical aspects of how HTTP and REST considers state however, this is a case where Cookies can be used in a REST-compliant manner. More specifically, Resp1 should include Set-Cookie headers specifying appropriate cookies to be set by the browser. Subsequently, the browser includes the cookies to Req2 and ultimately to Req3 so that they can be processed by the server.
  2. As part of the URL: The data that need to be passed to Req3 can be part of the redirection URL and subsequently to the Req3 URL. As URLs are primary elements of HTTP messages and are characterized by increased visibility (e.g. visible to the end user, logged into files/history, etc.), the information may need to be encoded or even encrypted before being included in the URL.

Presumably, there is a number of issues that should be considered when allowing the client to convey session-related state. For instance, trust between client and server is one of the most important ones. If the data that should be passed are sensitive, or should not be tampered by the client or any mediating component, then encryption techniques should be employed before passing the data to the client (either as Cookies or as part of the URLs).
Also, it should be understood that such a mechanism enforces an explicit dependency between the two pages, therefore the second page should not be able to be accessed without the provided cookie (i.e. the Req2 should fail if no Cookie has been specified).

Σχόλια

Δημοσίευση σχολίου

Δημοφιλείς αναρτήσεις από αυτό το ιστολόγιο

Counting Words, Characters and Lines with Notepad++

One of the best text editors in Windows is Notepad++ as it is lightweight, it provides a wealth of useful functionality –let alone the possible extensions through plugins. File Summary A useful feature of Notepad++ is that you can easily get a view on the size metrics of the document you are currently working on (characters, words, lines, etc). However, the menu is not that intuitive on finding that capability. So in order to get the above values you should go to: View >> Summary… The summary contains the following: Full path Created Modified File length (in byte) Characters (without blanks) Words Lines Current document length Selected Area Summary Nevertheless, the above summary provides file-level statistics and it may only provide the number of bytes and characters of a selected area. In order to count the word, characters, lines, etc. for just a selected part of the file you can install and use the TextFX Character plugin through the...

Software Engineering Stories blog: reborn

Well, to be honest, a few of years ago I created this blog with one primary intention: web logging software engineering stories that were taking place on the field.   Being an active software engineer/programmer/developer or code monkey, I was always spending time to trivial things that would be executed, forgotten and at some point needed to be rediscovered (or even reinvented) again and again. Or sometimes to inefficient approaches that myself or fellow programmers were following for which, at some point, I found a faster, easier or simpler way of executing them. Ultimately this blog was supposed to start with documenting trivial day-to-day operational task optimizations, or hacks, and proceed to more abstract software design or architecture discussions. And then it was abandoned due to a number of reasons. But now I'm back and excited to add useful, up-to-date content of software engineering stories, tricks and even unconventional  ways to accomplish this. As technolog...

Visual Studio 2015 and Git: part 1, cloning a repository

So, your manager sent you a URL and told you to go fix that little C# library that causes all that trouble, which, by the way, is hosted on a git server somewhere online. You have to send him back the new dll ASAP so that his promotion is not at stake. The bad news is that you have no clue how you do that -after all you are a Java developer and use SVN. The good news is that you found this blog. Worry no more, this 6-post-long quick guide is here for you to walk you through using the Visual Studio 2015 Git plugin to effortlessly accompish the following things: 1. clone a repository (presented in this post) 2. create a branch 3. commit changes 4. merge branches 5. pull changes from the repository 6. push your commited changes to the repository The idea here is to help beginners use the VS2015 Git plugin to quickly set up their environment so that their managers get their promotions and they skip studying the command-line git dissertation help pages or wandering thro...