This is a performance critical flow, so architectural decisions are based on performance.
Summary: From OpenResty, I need to proxy a request to service1 and on proxy reply I need to send a copy of the proxy reply to service2
Here is a simple ascii diagram of the flow:
Client ---> OR ---> Service1 -->--+
Client <--- OR -----<--------<----+
||
\/
Service2
For performance reasons (only want to parse URL params in Lua, not HTTP body) the load balancing from OR to Service1 will be done via balancer_by_lua_block and ngx.balancer.
Service1's response will be processed via body_filter_by_lua, which will copy the proxy reply and use ngx.timer.at to call a function that will do an internal ngx.location.capture to Service2 (which is BTW an internal OR location)
My question concerns whether this architecure is the most performant solution?
Is the body_by_filter_lua -> ngx.timer.at -> ngx.location.capture chain is the most efficient way to copy the proxy response and send it to Service2?
body_by_filter_lua does not allow cosockets, so I am using the ngx.timer.at trick to get around the cosocket limitation.
Additionally body chunks (ngx.arg[1]) in body_by_filter_lua will be concatenated into a single lua string and on final chunk sent to Service2.
This is an abnormal flow and my solution feels hacked together, so I am asking the community if there is a better (more efficient/performant) way of doing this flow?
thought?