System Design Flashcards

1
Q

Scalability

A

1 - Cached Database Queries

how do you go about making things faster
a) At server level

go for vertical scaling : more CPU, RAM and storage
or Horizontal scaling ..create identical servers .. then add a
load balancer in between .
In this case to ensure user experience is same when they are redirected to possibly different server . the session and profile data should be kept in some kind of networked storage . Better to not use file based storage ..so it can be a database or or it can be a distributed cache like Redis..

Next in this series is around Database .. how do you make it more performant

increase RAM .. SQL tuning , table denormalization ( to avoid joins) .. add replication .. master / slave setup.. slave is ready only and master for writes .

You can look at partitioning of data within a database( horizontal or vertical at rows or columns level)

When partitioning ..key for partitioning is most important .. say divide data based on time/data .. based on geography/country or customer id.

Sharding is basically doing that ( horizontal partioning) where data is kept across multiple db instances… now when querying you need something that identifies which shard it should be going to .. for example hash the key to find the shard

The Next thing done to improve scalability is caching . serving data from the cache to avoid the heavy db operation everytime. For a caching high level you can be storing data in cache related to a query per say or you could be doing Object level caching

Whenever you do a query to your database, you store the result dataset in cache. A hashed version of your query is the cache key. The next time you run the query, you first check if it is already in the cache.
Cons: When one piece of data changes (for example a table cell) you need to delete all cached queries who may include that table cell.

Let your class assemble a dataset from your database and then store the complete instance of the class or the assembed dataset in the cache.

for example, a class called “Product” which has a property called “data”. The property “data” is filled by several methods in the class doing several database requests.hen your class has finished the “assembling” of the data array, directly store the data array, or better yet the complete instance of the class, in the cache!

Some ideas of objects to cache:

user sessions (never use the database!)
fully rendered blog articles
activity streams
user<->friend relationships

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is SEDA

A

SEDA stands for Staged Event-Driven Architecture. Let me explain what it is and how Apache Camel implements it.
SEDA is an architectural pattern that:

Breaks processing into stages
Uses event queues between stages
Processes messages asynchronously
Allows concurrent processing at each stage
Provides natural load balancing and buffering

Apache Camel’s SEDA Implementation:

@Component
public class OrderProcessingRoute extends RouteBuilder {

Stage Independence

Each processing stage (validation, inventory, payment, fulfillment) operates independently
Different stages can have different throughput requirements
Failures in one stage don’t directly impact others

Concurrency Control

Different number of consumers per stage based on workload:
Validation: 3 consumers (lightweight operation)
Inventory: 5 consumers (more concurrent capacity for external service calls)
Payment: 4 consumers (balanced for payment processing)
Fulfillment: 3 consumers (final stage processing)

Load Management

Each queue has size limits to prevent memory issues
blockWhenFull=true prevents overflow in critical stages
Error handling with dead letter channel and retries

Performance Benefits

Async processing of orders through the pipeline
Natural load balancing across consumers
Buffering between stages handles speed mismatch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Whats the difference between openidconnect and oauth2

A

Example 1: Logging in to Spotify using Gmail
In this case, you are using your Google (Gmail) account to sign in to Spotify. This is an example of OpenID Connect in action.
When you click the “Sign in with Google” button on Spotify, the following happens:

Spotify (the client) requests authentication from Google (the authorization server).
Google authenticates you using your Google account credentials.
Google issues an ID token to Spotify, which contains information about your identity (your name, email, profile picture, etc.).
Spotify can then use this ID token to verify your identity and obtain your basic profile information, without you needing to create a separate Spotify account.

Here, OpenID Connect is used to authenticate you and provide information about your identity to Spotify.
Example 2: Connecting your Spotify account to your Facebook account
In this case, you are granting Spotify access to some of your Facebook data, without giving Spotify your Facebook login credentials.

Spotify (the client) requests authorization from you to access your Facebook data.
You authorize Spotify to access your Facebook data.
Facebook (the authorization server) issues an access token to Spotify, which Spotify can then use to access your Facebook data (e.g., your profile information, friend list, etc.).

Here, OAuth 2.0 is being used to authorize Spotify to access your Facebook data on your behalf, without exposing your Facebook login credentials.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Three development principles

A

KISS : keep it simple stupid
DRY : Do not repeat yourself. Change at one place
Yagni: You arent gonna need it. Dont over engineer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly