https://github.com/ngthecoder/simple_rpc_system
Cross-language RPC system with Go server and TypeScript client using TCP sockets and JSON serialization. Features concurrent handling, interactive CLI, and demonstrates microservice communication patterns.
https://github.com/ngthecoder/simple_rpc_system
distributed-systems golang rpc typescript
Last synced: 2 months ago
JSON representation
Cross-language RPC system with Go server and TypeScript client using TCP sockets and JSON serialization. Features concurrent handling, interactive CLI, and demonstrates microservice communication patterns.
- Host: GitHub
- URL: https://github.com/ngthecoder/simple_rpc_system
- Owner: ngthecoder
- License: mit
- Created: 2025-07-05T20:57:40.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-05T22:06:20.000Z (12 months ago)
- Last Synced: 2025-08-03T03:38:14.451Z (11 months ago)
- Topics: distributed-systems, golang, rpc, typescript
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README


# Cross-Language RPC System
A lightweight Remote Procedure Call (RPC) system enabling seamless communication between Go servers and TypeScript clients over TCP sockets.
## Why This Project?
Built to explore distributed systems concepts and demonstrate cross-language communication patterns used in microservices architectures.
## Features
- **Cross-Language Communication**: Go server and TypeScript client
- **TCP Socket Communication**: Direct, efficient network protocol
- **JSON-based Protocol**: Human-readable message format
- **Type Safety**: Strongly typed interfaces and structs
- **Interactive Client**: User-friendly command-line interface
- **Concurrent Server**: Handles multiple clients simultaneously using goroutines
- **Error Handling**: Robust error management and validation
## Tech Stack
- **Backend**: Go with native `net` package
- **Frontend**: TypeScript/Node.js with built-in networking
- **Protocol**: TCP sockets with JSON serialization
- **Concurrency**: Go goroutines for handling multiple clients
## Available RPC Functions
| Function | Parameters | Description | Example |
|----------|------------|-------------|---------|
| `floor` | `float` | Returns floor of a number | `floor(3.7)` returns `3` |
| `nroot` | `int, int` | Calculates nth root | `nroot(3, 27)` returns `3` |
| `reverse` | `string` | Reverses a string | `reverse("hello")` returns `"olleh"` |
| `validAnagram` | `string, string` | Checks if two strings are anagrams | `validAnagram("listen", "silent")` returns `true` |
| `sort` | `string[]` | Sorts array of strings | `sort(["c", "a", "b"])` returns `["a", "b", "c"]` |
## Quick Start
### Prerequisites
- Go 1.19+
- Node.js 16+
- npm
### 1. Clone the Repository
```bash
git clone https://github.com/ngthecoder/simple_rpc_system
cd simple_rpc_system
```
### 2. Start the Go Server
```bash
cd server
go run main.go
```
Server will start listening on `localhost:8090`
### 3. Set Up TypeScript Client
```bash
cd client
npm install
```
### 4. Run the Client
```bash
tsc client.ts
node client.js
```
### 5. Make RPC Calls
```
Enter method name: floor
Enter params (comma separated): 3.7
```
## Protocol Specification
### Request Format
```json
{
"method": "floor",
"params": [3.7],
"param_types": ["float"],
"id": 1
}
```
### Response Format
```json
{
"result": "3",
"result_type": "float64",
"id": 1
}
```
## Example Usage
**Client Input:**
```
Enter method name: nroot
Enter params (comma separated): 3, 27
```
**Network Communication:**
```json
// Request
{"method":"nroot","params":[3,27],"param_types":["int","int"],"id":42}
// Response
{"result":"3","result_type":"float64","id":42}
```
**Output:**
```
Sending: { method: 'nroot', params: [3, 27], param_types: ['int', 'int'] }
Connection Established
{"result":"3","result_type":"float64","id":42}
```
## Project Structure
```
rpc-system/
├── server/
│ └── main.go # Go RPC server
├── client/
│ ├── client.ts # TypeScript RPC client
│ ├── package.json # Node.js dependencies
│ └── package-lock.json # Dependency lock file
├── README.md
└── .gitignore
```
## Technical Implementation
### Server (Go)
- **Concurrent Handling**: Each client connection spawned in separate goroutine
- **JSON Unmarshaling**: Automatic parsing using struct tags
- **Function Registry**: Map-based function lookup and execution
- **Type Safety**: Interface{} with type assertions for dynamic typing
### Client (TypeScript)
- **Interactive CLI**: Readline interface for user input
- **Smart Parameter Parsing**: Function-specific input handling
- **Type Definitions**: Interfaces matching server protocol
- **Error Handling**: Network and parsing error management
## Future Enhancements
- [ ] Authentication and authorization
- [ ] HTTP REST API wrapper
- [ ] Client connection pooling
- [ ] Message compression
- [ ] Async/await client API
- [ ] Load balancing support
- [ ] Metrics and monitoring
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Learning Outcomes
This project demonstrates:
- **Network Programming**: TCP socket implementation
- **Serialization**: JSON protocol design
- **Concurrency**: Goroutine-based server architecture
- **Cross-Language Integration**: Communication between Go and TypeScript
- **System Design**: RPC architecture patterns
- **Error Handling**: Production-ready error management