# rpc error: code = ResourceExhausted desc = grpc: received message larger than max (5242881 vs. 4194304)

- **ID:** `go/grpc-resource-exhausted-max-message-size`
- **Domain:** go
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The serialized message exceeds the default 4 MiB receive limit. gRPC enforces MaxRecvMsgSize on both client and server.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Raise the limit on both sides: grpc.NewServer(grpc.MaxRecvMsgSize(16*1024*1024)) and grpc.Dial(addr, grpc.WithDefaultCallOptions(grpc.MaxRecvMsgSize(16*1024*1024))).
   ```
2. **** (85% success)
   ```
   Switch large payloads to gRPC streaming (client-streaming or server-streaming) so each message stays small, or store blobs out-of-band and pass a reference.
   ```

## Dead Ends

- **** — Compression reduces wire size but the decompressed message is still checked against MaxRecvMsgSize, so large payloads still fail. (70% fail)
- **** — The server also enforces the limit when receiving the request/response, so the error moves to the server side. (65% fail)
