Skip to contentমূল লেখায় যান

Topic 07 · Architectureটপিক 07 · Architecture

Stateless Service

Think of a bank with many counters. Your account is not in one clerk's memory but in the bank's central system, so any free clerk can serve you, and if one goes home, your money is still safe. A stateless service works the same way: app servers are the clerks, and the important data lives in a shared place. This page tells you what "stateless" means, where state goes, and what a tester can check.

5 min read5 মিনিটে পড়া যায় · 6 sections6টি সেকশন · 5 sources5টি সোর্স · updated Oct 2026আপডেট: Oct 2026

Why the second server forgets youদ্বিতীয় সার্ভার কেন আপনাকে ভুলে যায়

Move the session out of one server and the “logged out” bug disappears. Switch between memory, Redis and a JWT.সেশন একটা সার্ভারের বাইরে সরিয়ে নিন, তাহলে “লগ-আউট” বাগ চলে যায়। মেমরি, Redis আর JWT-র মধ্যে বদলে দেখুন।

2 min2 মিনিট6 steps6টি ধাপ
  • Servers that answerযে সার্ভার উত্তর দেয়1 / 2
  • Stay logged inলগ-ইন থাকে50 %
loginলগ-ইনyou · browserআপনি · ব্রাউজারServer 1সার্ভার 1(app)(অ্যাপ)Server 2সার্ভার 2(app)(অ্যাপ)RedisRedissessionsসেশন

You’ll learnআপনি শিখবেন

  • Why a second server can forget youদ্বিতীয় সার্ভার কেন ভুলে যেতে পারে
  • Where state can live instead: Redis or a JWTস্টেট কোথায় থাকতে পারে: Redis বা JWT
  • Why you can replace a server safelyকেন সার্ভার নিরাপদে বদলানো যায়
  • What a tester checks: bad tokens fail with 401টেস্টার কী দেখে: ভুল টোকেন 401 দেয়

In plain words

"State" is data that must survive from one request to the next. The most common example is a session. A session is the data of one user that stays between requests while the user works in the app Source 1সোর্স 1. A stateless application does not need to know about earlier requests, and it does not keep session data itself Source 1সোর্স 1.

The state does not disappear. A stateless service moves it out of the app server. Then no request depends on data on the local disk or in the local memory of one server. So you can replace a server at any time, and users do not notice Source 1সোর্স 1. Because any server can answer any request, you can scale horizontally Source 1সোর্স 1.

Where does the state go? Here are the usual places:

StateShared place
Login sessionA shared cache or a database Source 1সোর্স 1. Redis can work as a session store Source 3সোর্স 3.
Token dataA JWT, a token that carries claims between two parties Source 4সোর্স 4
Uploaded filesObject storage, such as Amazon S3 Source 1সোর্স 1
Slow or heavy workBackground jobs, outside the request Source 2সোর্স 2

With a session store, the browser keeps a cookie. The app uses the cookie as a key to find the session data in the shared store Source 3সোর্স 3.

A JWT (JSON Web Token) is a short, URL-safe string that carries claims, such as "this is user 42" Source 4সোর্স 4. The claims can be digitally signed Source 4সোর্স 4. A server that has the key can check the signature. If a check step fails, the server must reject the token Source 4সোর্স 4. So the server can trust a valid token without a session in its own memory. A JWT can also have an expiry time (exp). After that time, the server must not accept the token Source 4সোর্স 4.

Sequence diagram with five parts: User, Load Balancer, App Server 1, App Server 2, and Redis Session Store. In the login flow, the user sends a login request to the load balancer, which forwards it to App Server 1. App Server 1 stores the session or token data in Redis. In the next request flow, the load balancer forwards the request to App Server 2. App Server 2 validates the session in Redis, and Success goes back to the user.Open the image in full sizeছবিটি পূর্ণ আকারে খুলুন

সহজ English

"State" is data that must stay from one request to the next. The most common example is a session: the data of one user that stays between requests Source 1সোর্স 1. A stateless app does not keep session data itself Source 1সোর্স 1.

The state moves out of the app server. No request needs data on the disk or in the memory of one server. So you can replace a server at any time, and users do not notice Source 1সোর্স 1. Any server can answer any request, so you can scale horizontally Source 1সোর্স 1.

বাংলা ব্যাখ্যা

"State" হলো এমন data, যা একটি request থেকে পরের request পর্যন্ত টিকে থাকতে হয়। সবচেয়ে পরিচিত উদাহরণ হলো session। Session হলো একজন user-এর data, যা user app-এ কাজ করার সময় request-গুলোর মাঝে থেকে যায় Source 1সোর্স 1। একটি stateless application-কে আগের request-এর কথা জানতে হয় না, এবং এটি নিজে session data রাখে না Source 1সোর্স 1।

State হারিয়ে যায় না। Stateless service এটিকে app server-এর বাইরে সরিয়ে দেয়। তখন কোনো request একটি server-এর local disk বা local memory-র data-র উপর নির্ভর করে না। তাই আপনি যেকোনো সময় একটি server বদলে দিতে পারেন, আর user-রা টেরও পান না Source 1সোর্স 1। যেকোনো server যেকোনো request-এর উত্তর দিতে পারে বলে আপনি horizontally scale করতে পারেন Source 1সোর্স 1।

State সাধারণত এই জায়গাগুলোতে যায়:

JWT (JSON Web Token) হলো একটি ছোট, URL-safe string, যা claim বহন করে, যেমন "this is user 42" Source 4সোর্স 4। Claim-গুলো digitally signed হতে পারে Source 4সোর্স 4। যে server-এর কাছে key আছে, সেটি signature check করতে পারে। কোনো check ধাপ fail করলে server-কে token-টি reject করতে হবে Source 4সোর্স 4। তাই server নিজের memory-তে session না রেখেও একটি valid token-কে বিশ্বাস করতে পারে। JWT-তে একটি expiry time (exp) থাকতে পারে; সেই সময়ের পরে server token-টি গ্রহণ করবে না Source 4সোর্স 4।

When you need it

  • You want horizontal scaling, with many app servers behind a load balancer.
  • You want rolling deployments, where servers restart one at a time.
  • User sessions must survive a server restart.
  • You use cloud or container platforms. AWS says that once an app is stateless, you can run it on serverless compute such as AWS Lambda or AWS Fargate Source 1সোর্স 1.

সহজ English

You need a stateless service in these cases:

  • You want horizontal scaling: many app servers behind a load balancer.
  • You want rolling deployments. In a rolling deployment, the servers restart one at a time.
  • User sessions must survive when a server restarts.
  • You use cloud or container platforms. AWS says that when an app is stateless, you can run it on serverless compute, such as AWS Lambda or AWS Fargate Source 1সোর্স 1.

বাংলা ব্যাখ্যা

নিচের অবস্থাগুলোতে আপনার একটি stateless service দরকার:

  • আপনি horizontal scaling চান, অর্থাৎ একটি load balancer-এর পেছনে অনেকগুলো app server।
  • আপনি rolling deployment চান, যেখানে server-গুলো একটি একটি করে restart হয়।
  • একটি server restart হলেও user session-গুলো টিকে থাকতে হবে।
  • আপনি cloud বা container platform ব্যবহার করেন। AWS বলে, একটি app stateless হয়ে গেলে আপনি সেটিকে AWS Lambda বা AWS Fargate-এর মতো serverless compute-এ চালাতে পারেন Source 1সোর্স 1।

A real-life example

A student logs in to the LMS through App Server 1. The next request goes to App Server 2.

If the session is only in the memory of App Server 1, App Server 2 does not know the student. The student seems logged out and must log in again. Now the team moves the sessions to Redis. App Server 1 writes the session to Redis at login. App Server 2 reads the same session from Redis and accepts the request. A JWT gives the same result: App Server 2 checks the token signature and accepts the request.

সহজ English

A student logs in to the LMS through App Server 1. The next request goes to App Server 2.

If the session is only in the memory of App Server 1, App Server 2 does not know the student. The student seems logged out and must log in again.

Now the team moves the sessions to Redis. At login, App Server 1 writes the session to Redis. App Server 2 reads the same session from Redis and accepts the request.

A JWT gives the same result. App Server 2 checks the token signature and accepts the request.

বাংলা ব্যাখ্যা

ধরুন, একজন শিক্ষার্থী App Server 1-এর মাধ্যমে LMS-এ log in করে। পরের request-টি যায় App Server 2-এ।

Session যদি শুধু App Server 1-এর memory-তে থাকে, তাহলে App Server 2 শিক্ষার্থীকে চেনে না। শিক্ষার্থীকে logged out মনে হয়, এবং তাকে আবার log in করতে হয়।

এখন team session-গুলো Redis-এ সরিয়ে নেয়। Login-এর সময় App Server 1 session-টি Redis-এ লেখে। App Server 2 Redis থেকে একই session পড়ে এবং request-টি গ্রহণ করে। JWT দিয়েও একই ফল পাওয়া যায়: App Server 2 token-এর signature check করে এবং request-টি গ্রহণ করে।

Common mistakes

  • Sessions in local memory. Users seem logged out when the next request goes to another server. Microsoft names session state in memory as a cause of "stickiness" Source 2সোর্স 2.
  • Uploaded files on the local disk. The file exists on one server only.
  • Background jobs inside the app process. A heavy task slows down the user requests on that server. Move high-CPU or high-I/O tasks to background jobs Source 2সোর্স 2.
  • The same cron job on every server. A cron job is a task that runs on a schedule. With three servers, the nightly email can go out three times.
  • Sticky sessions to hide a weak design. A sticky session (session affinity) makes the load balancer send all requests of one user to the same server Source 5সোর্স 5. AWS says this is useful for servers that keep state Source 5সোর্স 5. But stickiness limits scale-out Source 2সোর্স 2, and the user still loses the session when that server dies.

সহজ English

Look out for these common mistakes:

  • Sessions in local memory. When the next request goes to another server, users seem logged out. Microsoft names session state in memory as a cause of "stickiness" Source 2সোর্স 2.
  • Uploaded files on the local disk. The file is on one server only.
  • Background jobs inside the app process. A heavy task makes the user requests on that server slow. Move tasks with high CPU or high I/O use to background jobs Source 2সোর্স 2.
  • The same cron job on every server. A cron job is a task that runs on a schedule. With three servers, the nightly email can go out three times.
  • Sticky sessions to hide a weak design. With a sticky session (session affinity), the load balancer sends all requests of one user to the same server Source 5সোর্স 5. AWS says that this is useful for servers that keep state Source 5সোর্স 5. But stickiness limits scale-out Source 2সোর্স 2. Also, the user still loses the session when that server dies.

বাংলা ব্যাখ্যা

এই সাধারণ ভুলগুলোর দিকে খেয়াল রাখুন:

  • Local memory-তে session। পরের request অন্য server-এ গেলে user-দের logged out মনে হয়। Microsoft memory-তে থাকা session state-কে "stickiness"-এর একটি কারণ হিসেবে উল্লেখ করে Source 2সোর্স 2।
  • Local disk-এ upload করা file। File-টি শুধু একটি server-এ থাকে।
  • App process-এর ভেতরে background job। একটি ভারী কাজ সেই server-এর user request-গুলোকে ধীর করে দেয়। বেশি CPU বা বেশি I/O লাগে এমন কাজ background job-এ সরিয়ে দিন Source 2সোর্স 2।
  • প্রতিটি server-এ একই cron job। Cron job হলো এমন একটি কাজ, যা একটি schedule অনুযায়ী চলে। তিনটি server থাকলে রাতের email তিনবার চলে যেতে পারে।
  • দুর্বল design আড়াল করতে sticky session। Sticky session (session affinity) থাকলে load balancer একজন user-এর সব request একই server-এ পাঠায় Source 5সোর্স 5। AWS বলে, state রাখে এমন server-এর জন্য এটি কাজের Source 5সোর্স 5। কিন্তু stickiness scale-out সীমিত করে Source 2সোর্স 2, আর সেই server নষ্ট হয়ে গেলে user তবুও session হারান।

What a tester can check

Tutorial advice

These test ideas are the tutorial's own advice.

  • Server hop. Log in, then send requests that land on different servers. Check that the user stays logged in on each one.
  • Restart during a session. Restart one app server, or all of them one by one. Check that logged-in users stay logged in.
  • Token expiry. Send a request with an expired JWT, and with a JWT that has one changed character. Both must fail with 401.
  • Logout everywhere. Log out, then replay the old cookie or token. Check that no server still accepts it.
  • Duplicate jobs. Run three servers and wait for a scheduled job. Check that it runs only one time.
  • Sticky sessions off. In a test environment, turn off sticky sessions. Run the main user flows and look for lost data.

সহজ English

These test ideas are the tutorial's own advice.

  • Server hop. Log in. Then send requests that go to different servers. Make sure that the user stays logged in on each server.
  • Restart during a session. Restart one app server, or restart all of them one after the other. Make sure that logged-in users stay logged in.
  • Token expiry. Send a request with an expired JWT. Then send a request with a JWT that has one changed character. Both requests must fail with 401.
  • Logout everywhere. Log out. Then send the old cookie or token again. Make sure that no server still accepts it.
  • Duplicate jobs. Run three servers and wait for a scheduled job. Make sure that the job runs only one time.
  • Sticky sessions off. In a test environment, turn off sticky sessions. Run the main user flows and look for lost data.

বাংলা ব্যাখ্যা

নিচের test ধারণাগুলো এই tutorial-এর নিজস্ব পরামর্শ।

  • Server বদল। Log in করুন, তারপর এমন request পাঠান যা ভিন্ন ভিন্ন server-এ যায়। দেখুন, প্রতিটি server-এ user logged in থাকে কি না।
  • Session চলার সময় restart। একটি app server restart করুন, অথবা সবগুলো একটি একটি করে restart করুন। দেখুন, logged-in user-রা logged in থাকেন কি না।
  • Token expiry। একটি মেয়াদোত্তীর্ণ JWT দিয়ে একটি request পাঠান, আর একটি character বদলানো JWT দিয়ে আরেকটি request পাঠান। দুটিই 401 দিয়ে fail করতে হবে।
  • সব জায়গা থেকে logout। Log out করুন, তারপর পুরনো cookie বা token আবার পাঠান। দেখুন, কোনো server এখনও সেটি গ্রহণ করে কি না।
  • Duplicate job। তিনটি server চালান এবং একটি scheduled job-এর জন্য অপেক্ষা করুন। দেখুন, সেটি শুধু একবার চলে কি না।
  • Sticky session বন্ধ। একটি test environment-এ sticky session বন্ধ করুন। মূল user flow-গুলো চালান এবং হারানো data খুঁজুন।

Key words

WordMeaning
StateData that must survive from one request to the next
SessionThe data of one user that stays between requests
Stateless serviceAn app server that keeps no important state in its own memory or disk
Session storeA shared place, such as Redis, that keeps the sessions for all servers
JWTJSON Web Token: a signed string that carries claims about the user
ClaimOne piece of information in a token, such as the user id
Sticky sessionThe load balancer sends all requests of one user to the same server
Cron jobA task that runs on a schedule

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

  1. [1]
    REL05-BP06 Make systems stateless where possible

    AWS Well-Architected Framework · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  2. [2]
    Design to scale out

    Microsoft Azure Architecture Center · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  3. [3]
    What is Azure Cache for Redis?

    Microsoft Learn · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  4. [4]
    RFC 7519: JSON Web Token (JWT)

    IETF · accessed 2026-10-20দেখা হয়েছে: 2026-10-20

  5. [5]
    Edit target group attributes for your Application Load Balancer

    AWS Documentation · accessed 2026-10-20দেখা হয়েছে: 2026-10-20