Howard Creative Co
← Back to Blog

Webhook Service | How To Approach System Design Interview + Practical Examplecategory

system-design 5 min read
Webhook Service | How To Approach System Design Interview + Practical Examplecategory

![Cover Image](/og-images/articles/webhook-service.png)

Introduction

System design is how you plan before you build. Not just code, but full picture: features, traffic, failures, scale and security. When you grow in level, company want you to think more, not just do more. Junior build, senior design before build. That's why system design interview show how senior you think.

![Funny Illustration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rsd8279j4iucs0kcp0dq.png)

🔥 Motivation

Recently I've been in a system design interview where, despite having most of the technical knowledge covered like queues, load balancers, API gateways, workers it wasn't the best experience due to lack of proper structure in answering system design questions. So, instead regretting the past, let's ensure better future experiences!

How To Approach a System Design Interview

| 💡 Tip: Interviewer will definitely maintain an atmosphere of ambiguity and open ended scope, so instead of being confused, embrace it to show how well your thinking process is, and how you deal with problems as a true software engineer | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

Step 1: Understand the Problem

First thing, don't rush. Listen careful to what the interviewer is asking for. Ask questions back if something is not clear. Make sure you 100% understand what you need to build before you start talking.

Step 2: Define & Split Requirements To Two Parts

Communicate them well, so the interviewer see you are thinking in full picture.

Step 3: Address Functional Requirements & High Level Design

Step 4: Address Non Functional Requirements & Low Level Design

| 💡 Tip: It would be really beneficial especially at big companies if you can do some calculations regarding memory, throughput, how many requests per second the system can handle and those stuff using techniques like [Back of the envelope calculations](https://highscalability.com/google-pro-tip-use-back-of-the-envelope-calculations-to-choo/) | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

Practical Example: Design a Webhook Service

Step 1: Understand the Problem

Webhooks are way to get real-time updates from other systems. Unlike normal APIs where we keep asking: Any updates?... yooo anything new?.... webhooks push data to us when something happens. For example, Stripe sends us webhook when payment done, Shopify when order ships, GitHub when code pushed.

Step 2: Define & Split Requirements

#### Functional Requirements

#### Non-Functional Requirements

Step 3: Address Functional Requirements & High Level Design

Let's start with basic design. When external system sends webhook event, our service needs to:

1. Have API endpoint to receive event 2. Process it 3. Save it to database

Basic design looks like:

![High Level Design](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1bi6nte7z6dswms8fjwe.png)

But this design has problem: if handler fails after processing but before saving to database, we lose the event.

Better design with message queue:

![Low Level Design](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8chyydmqbewdt17rxz82.png)

How this works:

1. External system sends event to our API 2. Request Handler accepts event and puts in message queue 3. Request Handler sends 200 OK response 4. Queue Consumer takes event from queue 5. Queue Consumer processes event 6. Queue Consumer saves result to database 7. Once saved, event removed from queue

Step 4: Address Non-Functional Requirements & Low Level Design

#### Handling Failures

##### Request Handler Failures

##### Message Queue Failures

##### Queue Consumer Failures

##### Database Failures

#### Security Concerns

1. HMAC Signatures:

2. IP Whitelisting:

3. Rate Limiting:

#### Handling Duplicate and Out-of-Order Requests

##### For Duplicates

##### For Out-of-Order Events

By following these steps, we create webhook service that's reliable, secure, and handles real-world problems like failures, duplicates, and out-of-order events.

Acknowledgment

← Back to Blog