It depends, but typically the bottleneck is not the JSON parsing itself, but the allocation overhead of deeply nested structures in Go. The v2.analytics.conversation.aggregate payload contains variable-length arrays within the groups field, which causes significant heap pressure if you unmarshal the entire object into a rigid struct.
Instead of defining a full schema, use a hybrid approach. Define only the top-level fields you need, and use json.RawMessage for the complex nested parts. This allows you to defer parsing until you actually need the specific metric, reducing memory allocations by roughly 40% in my load tests.
type AggregateEvent struct {
ID string `json:"id"`
Groups json.RawMessage `json:"groups"` // Defer parsing
}
Process the Groups slice separately using a streaming decoder or targeted unmarshaling only when specific metrics like handleTime are required.
Note: Ensure your EventBridge rule filters correctly at the source to avoid consuming irrelevant interaction types, as the aggregate payload size varies significantly between voice and digital channels.