> For the complete documentation index, see [llms.txt](https://build-your-own-redis.rijalasepnugroho.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://build-your-own-redis.rijalasepnugroho.com/readme.md).

# Build Your Own Redis with Go

Panduan Software Engineer Membangun In-Memory Database dengan Golang

> 🏺 "Pendem" - Sebuah kata dari bahasa Jawa yang berarti "menyimpan di dalam tanah". Seperti namanya, Pendem adalah cache server yang menyimpan data dengan kokoh, aman, dan cepat di dalam memory.

## 📖 Tentang Buku Ini

Buku ini adalah panduan langkah demi langkah untuk membangun Redis-like cache server dari awal menggunakan bahasa Go. Dimulai dari socket programming, RESP protocol, hingga fitur-fitur canggih seperti persistence, sharding, dan cluster support.

Hasil akhir dari buku ini adalah **Pendem Database** - sebuah cache engine production-ready yang bisa Anda gunakan, modifikasi, dan pelajari.

## 🎯 Target Pembaca

* Software Engineer yang ingin memahami cara kerja cache database
* Go Developer yang ingin belajar network programming
* Backend Engineer yang ingin membangun sistem terdistribusi
* Mahasiswa yang ingin belajar arsitektur database

Prasyarat:

* Dasar-dasar bahasa Go (struct, interface, goroutine, channel)
* Pemahaman dasar networking (TCP/IP)
* Familiar dengan command line

## 📚 Daftar Isi

| Bab    | Topik                    | Deskripsi                                                   |
| ------ | ------------------------ | ----------------------------------------------------------- |
| Bab 1  | Pengenalan               | Arsitektur Redis, desain Pendem, dan persiapan              |
| bab 2  | Golang Fundamental       | Dasar - dasar golang                                        |
| Bab 3  | Socket Programming       | TCP server, connection handling, graceful shutdown          |
| Bab 4  | RESP Protocol            | Redis Serialization Protocol, parser & encoder              |
| Bab 5  | In-Memory Storage        | Cache engine, TTL, dan background cleanup                   |
| Bab 6  | LRU Eviction             | Least Recently Used eviction policy                         |
| Bab 7  | Sharding                 | Concurrent access, multi-core utilization                   |
| Bab 8  | Persistence              | JSON snapshot, RDB, AOF, dan recovery                       |
| Bab 9  | Data Structures          | Hash, List, Set, dan Sorted Set                             |
| Bab 10 | Batch Operations         | MGET, MSET, Pipeline                                        |
| Bab 11 | Transaction              | MULTI, EXEC, WATCH                                          |
| Bab 12 | Pub/Sub & Queue          | Real-time messaging dan task distribution                   |
| Bab 13 | Monitoring               | Metrics, logging, dan observability                         |
| Bab 14 | Clustering (coming soon) | CLustering support, service discovery, gossip protocol, etc |

## 🏗️ Arsitektur Pendem

```
┌─────────────────────────────────────────────────────────────────┐
│                         PENDEM                                  │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │                    TCP Server                           │   │
│   │  ┌───────────────────────────────────────────────────┐  │   │
│   │  │              RESP Protocol Parser                 │  │   │
│   │  └───────────────────────────────────────────────────┘  │   │
│   └─────────────────────────────────────────────────────────┘   │
│                              │                                  │
│                              ▼                                  │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │                   Command Handlers                      │   │
│   │  PING │ GET │ SET │ DEL │ TTL │ MEMORY │ POLICY         │   │
│   │  HSET │ HGET │ LPUSH │ RPUSH │ SADD │ ZADD │ ...        │   │
│   └─────────────────────────────────────────────────────────┘   │
│                              │                                  │
│                              ▼                                  │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │                  Sharded Cache                          │   │
│   │  ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┐     │   │
│   │  │ S0   │ S1   │ S2   │ S3   │ S4   │ S5   │ S6   │     │   │
│   │  │ LRU  │ LRU  │ LRU  │ LRU  │ LRU  │ LRU  │ LRU  │     │   │
│   │  └──────┴──────┴──────┴──────┴──────┴──────┴──────┘     │   │
│   └─────────────────────────────────────────────────────────┘   │
│                              │                                  │
│                              ▼                                  │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │                   Persistence                           │   │
│   │  ┌───────────┐  ┌───────────┐  ┌───────────┐            │   │
│   │  │   JSON    │  │   RDB     │  │   AOF     │            │   │
│   │  │ Snapshot  │  │  Binary   │  │   Log     │            │   │
│   │  └───────────┘  └───────────┘  └───────────┘            │   │
│   └─────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────┘
```

## 🗺️ Roadmap Pembelajaran

```
┌─────────────────────────────────────────────────────────────────┐
│                    LEARNING ROADMAP                             │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   📚 CORE FUNDAMENTALS                                          │
│   ├─ Bab 3: Socket Programming                                  │
│   ├─ Bab 4: RESP Protocol                                       │
│   └─ Bab 5: In-Memory Storage                                   │
│                                                                 │
│   📚 ADVANCED FEATURES                                          │
│   ├─ Bab 6: LRU Eviction                                        │
│   ├─ Bab 7: Sharding                                            │
│   └─ Bab 8: Persistence                                         │
│                                                                 │
│   📚 DATA STRUCTURES & PERFORMANCE                              │
│   ├─ Bab 9: Data Structures                                     │
│   ├─ Bab 10: Batch Operations                                   │
│   └─ Bab 11: Transaction                                        │
│                                                                 │
│   📚 REAL-TIME & DISTRIBUTED                                    │
│   ├─ Bab 12: Pub Sub & Queue                                    │
│   └─ Bab 13: Clustering Support                                 │
│                                                                 │
│   🚀 PENDEM IS COMPLETE!                                        │
└─────────────────────────────────────────────────────────────────┘
```

## 📁 Struktur Kode

```

pendem/
├── cmd/
│   └── main.go
├── internal/
│   ├── config/
│   │   └── config.go
│   ├── engine/
│   │   ├── cache.go
│   │   ├── item.go
│   │   ├── lru.go
│   │   ├── shard.go
│   │   ├── hash.go
│   │   ├── list.go
│   │   ├── set.go
│   │   └── sortedset.go
│   ├── handler/
│   │   ├── handler.go
│   │   ├── hash.go
│   │   ├── list.go
│   │   ├── set.go
│   │   └── sortedset.go
│   ├── persistence/
│   │   ├── manager.go
│   │   ├── json.go
│   │   ├── rdb.go
│   │   └── aof.go
│   ├── pubsub
│   │   └── pubsub.go
│   └── server/
│       ├── server.go
│       ├── connection.go
│       └── resp.go
├── test/
│   └── integration/
│       └── concurrency_test.go
├── go.mod
├── go.sum
└── README.md
```

## 🚀 Hasil Akhir: Pendem Database

Pendem adalah cache server yang dibangun dari buku ini. Dengan fitur:

| Fitur                      | Status                              |
| -------------------------- | ----------------------------------- |
| RESP Protocol              | ✅ Full Redis-compatible             |
| TCP Server                 | ✅ Concurrent with graceful shutdown |
| In-Memory Storage          | ✅ TTL support                       |
| Eviction                   | ✅ Memory-aware (lru, lfu. ttl)      |
| Sharding                   | ✅ 16 shards for parallelism         |
| Persistence                | ✅ JSON + RDB + AOF                  |
| Hash, List, Set, SortedSet | ✅ Complete implementation           |
| Batch Operations           | ✅ MGET, MSET, Pipeline              |
| Config File                | ✅ pendem.conf support               |
| Transaction                | ✅ MULTI, EXEC, WATCH                |
| Real Time                  | ✅ Pub/sub & Queue                   |
| Cluster                    | ✅ Support Clustering                |
| Monitoring                 | ✅ Metric & Observability            |

## 📂 Repository

Source Code: [github.com/jacky-htg/pendem](https://github.com/jacky-htg/pendem)

## 📄 Lisensi

Buku ini dilisensikan di bawah [GNU GPL License](https://github.com/jacky-htg/build-your-own-redis-with-go/tree/main/LICENSE/README.md).

## 📬 Kontak

* Author: Rijal Asepnugroho (Jacky Htg)
* GitHub: jacky-htg
* Repository: github.com/jacky-htg

🏺 Pendem - Cache Server yang Kokoh Seperti Tanah


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://build-your-own-redis.rijalasepnugroho.com/readme.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
