Performance Engineering and Cost Optimization Questions
Engineering practices and trade offs for meeting performance objectives while controlling operational cost. Topics include setting latency and throughput targets and latency budgets; benchmarking profiling and tuning across application database and infrastructure layers; memory compute serialization and batching optimizations; asynchronous processing and workload shaping; capacity estimation and right sizing for compute and storage to reduce cost; understanding cost drivers in cloud environments including network egress and storage tiering; trade offs between real time and batch processing; and monitoring to detect and prevent performance regressions. Candidates should describe measurement driven approaches to optimization and be able to justify trade offs between cost complexity and user experience.
Sample Answer
Sample Answer
import orjson
# serialize
b = orjson.dumps(obj) # returns bytes (no extra str copy)
# deserialize
obj = orjson.loads(b)# streaming encode to a file-like object to avoid building a huge string
import json
def stream_write(obj, fp):
json.dump(obj, fp) # writes incrementally to fp# ijson for streaming parsing of very large JSON
import ijson
with open('big.json', 'rb') as f:
for item in ijson.items(f, 'records.item'):
process(item)Sample Answer
# parameters
NUM_BUCKETS = 6 # sliding window buckets (e.g., last 6 minutes)
M = 2_000_000 # bit-array size
K = 4 # number of hash functions
COUNTER_BITS = 4 # counters per cell (max 15)
# data structures
buckets = [array_of_uint(COUNTER_BITS, M) for _ in range(NUM_BUCKETS)]
current = 0
def hash_indices(id):
# produce K indices using two independent hashes (double hashing)
h1 = hash1(id)
h2 = hash2(id)
return [(h1 + i*h2) % M for i in range(K)]
def is_duplicate(event_id):
indices = hash_indices(event_id)
# present if any bucket has all counters > 0 at those indices
for b in buckets:
if all(b[idx] > 0 for idx in indices):
return True
return False
def insert(event_id):
indices = hash_indices(event_id)
for idx in indices:
# saturating increment to avoid overflow
buckets[current][idx] = min(buckets[current][idx] + 1, (1 << COUNTER_BITS) - 1)
def advance_bucket():
# expire oldest by zeroing the next bucket and rotate
current = (current + 1) % NUM_BUCKETS
buckets[current].zero()Sample Answer
Sample Answer
Unlock Full Question Bank
Get access to hundreds of Performance Engineering and Cost Optimization interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.