Serverless Architecture and Functions as a Service Questions
Covers architectural and operational aspects of serverless computing and Functions as a Service platforms such as Lambda, Cloud Functions, and Azure Functions. Topics include event driven design patterns, stateless versus stateful approaches, state management strategies, serverless friendly data stores, function lifecycle and cold start behavior, concurrency and scaling characteristics, cost and billing models, vendor lock in and portability concerns, integration with messaging and event buses, security and permission models, observability and monitoring for ephemeral compute, and decision criteria for choosing serverless versus traditional compute or container based deployments. Candidates should be able to reason about trade offs, design event driven backends, and propose operational practices to manage reliability and performance in serverless environments.
Sample Answer
Sample Answer
Sample Answer
import threading
import asyncio
from functools import wraps
from collections import OrderedDict
# PSEUDO: boto3 client = dynamodb
class LRUCache:
def __init__(self, max_items=1000):
self.max = max_items
self.lock = threading.RLock()
self.data = OrderedDict()
def get(self, k):
with self.lock:
v = self.data.get(k)
if v is not None:
self.data.move_to_end(k)
return v
def set(self,k,v):
with self.lock:
self.data[k]=v
self.data.move_to_end(k)
if len(self.data)>self.max:
self.data.popitem(last=False)
inflight = {} # key -> asyncio.Event or threading.Event
inflight_lock = threading.Lock()
cache = LRUCache(max_items=500)
def fetch_from_dynamo(key):
# blocking call to DynamoDB, return feature vector or None
pass
def spawn_async_refresh(key):
# schedule background task to fetch and set cache
async def refresh():
val = await asyncio.to_thread(fetch_from_dynamo, key)
if val is not None:
cache.set(key, val)
with inflight_lock:
ev = inflight.pop(key, None)
if ev: ev.set()
asyncio.create_task(refresh())
def feature_cache_decorator(fn):
@wraps(fn)
def wrapper(key, *args, **kwargs):
# 1) try in-memory cache
val = cache.get(key)
if val is not None:
return fn(val, *args, **kwargs)
# 2) check if another refresh in-flight
with inflight_lock:
ev = inflight.get(key)
if ev is None:
ev = threading.Event()
inflight[key]=ev
primary = True
else:
primary = False
if primary:
# fetch synchronously (to serve current request) then spawn async refresh to refresh later
val = fetch_from_dynamo(key)
if val is not None:
cache.set(key, val)
# mark done for waiters
with inflight_lock:
ev = inflight.pop(key, None)
if ev: ev.set()
# launch background refresh to keep cache fresh (non-blocking)
try:
spawn_async_refresh(key)
except Exception:
pass
return fn(val, *args, **kwargs)
else:
# wait briefly to let primary fill cache (avoid long block)
ev.wait(timeout=0.5)
val = cache.get(key)
if val is not None:
return fn(val, *args, **kwargs)
# fallback: synchronous read from DynamoDB if still missing
val = fetch_from_dynamo(key)
if val is not None:
cache.set(key, val)
return fn(val, *args, **kwargs)
return wrapperSample Answer
Sample Answer
Unlock Full Question Bank
Get access to hundreds of Serverless Architecture and Functions as a Service interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.