Home

Perrequest

Perrequest, often written as per-request, is a design principle in software engineering referring to the lifecycle and management of data, resources, or services tied to the duration of a single client request. In web architectures, a request typically starts when the server receives an HTTP call and ends when the response is sent. Perrequest handling emphasizes that each request is isolated from others unless information is shared through external state such as a database or cache.

In practice, many frameworks support per-request scope by instantiating new objects for each incoming request and

Benefits include better isolation, simpler reasoning about state, and reduced risk of data leakage between requests.

Guidelines: prefer perrequest scope for data that is inherently request-scoped (authentication context, transaction scope, request data).

Related concepts include per-session (state across multiple requests for a user session) and per-connection (state tied

disposing
of
them
at
the
end
of
the
request.
This
is
commonly
implemented
through
dependency
injection
containers
using
a
scoped
or
per-request
lifetime.
Objects
created
for
one
request
are
not
reused
for
subsequent
requests,
reducing
leakage
of
request-specific
state
and
improving
thread
safety.
Drawbacks
include
resource
overhead
from
frequent
construction
and
teardown,
and
the
need
to
manage
lifetimes
and
disposal
carefully
to
avoid
leaks
or
unfinished
operations.
Use
stateless
components
when
possible
and
leverage
external
storage
for
cross-request
data.
For
performance-critical
paths,
combine
per-request
design
with
pooling
or
reuse
strategies
where
appropriate,
ensuring
that
pooled
resources
are
not
incorrectly
shared
between
requests.
to
a
network
connection).
Perrequest
is
a
core
concept
in
web
frameworks
such
as
ASP.NET
Core,
Spring,
Django,
and
many
DI
systems
that
offer
scoped
lifetimes.
It
is
also
a
consideration
in
distributed
tracing
and
auditing,
where
per-request
identifiers
are
propagated
across
services.