How We Built a Scalable Apache APISIX Gateway on the 360 Platform
This article details the 360 team’s decision to adopt Apache APISIX for their gateway layer, describes the production architecture, containerized deployment steps, plugin development workflow, and operational metrics, providing a practical guide for building and managing a high‑performance API gateway.
API Gateway Selection
In October 2019 our team set out to redesign the gateway layer of the 360 basic operation platform, evaluating popular open‑source gateways such as Kong, Orange, and Apache APISIX, and ultimately selecting APISIX because its etcd‑based storage matched our requirements.
Online Running Status
We now manage close to 900 APIs with a daily PV of about 10 million; monitoring shows both the gateway and all micro‑services are operating smoothly.
Gateway POD monitoring and micro‑service load graphs confirm stable performance.
Architecture Diagram
The final architecture places the gateway service on our container cloud, while the etcd cluster runs on three virtual machines.
Containerized Development and Deployment
We built a custom OpenResty image that includes required APISIX dependencies, installed APISIX 0.9, and then demonstrated the full deployment process.
docker run -itd -p 9080:9080 -p9443:9443 --name myapisix hulklab/openresty:0.0.1docker exec -it myapisix bashluarocks install apisix 0.9-0# apisix 0.9-0 is now installed in /usr/local (license: Apache License 2.0)cd /usr/local/apisixls -ldrwxr-xr-x 3 root root 4096 Dec 18 11:52 confdrwxr-xr-x 2 root root 4096 Dec 18 11:37 logsapisix startps aux|grep openrestyIf apisix start fails, start etcd first and adjust etcd.host in /usr/local/apisix/conf/config.yaml .
#config.yaml:69etcd:host: "http://172.17.0.1:2379" # etcd addressPlugin Development Overview
Our project separates business code from APISIX core code, allowing independent upgrades. The lua/apisix/plugins directory holds custom plugins, while lua/libs stores shared libraries. The following plugins are used:
ip-restriction (access_by_lua)
basic-auth (access_by_lua, custom)
web-auth (access_by_lua, custom)
limit-rate (access_by_lua, custom)
proxy-rewrite (access_by_lua, balancer_by_lua, custom)
log (log_by_lua, custom)
alarm (log_by_lua, custom)
Basic‑Auth Plugin Sample
The plugin defines a single enable parameter to allow fine‑grained control when the plugin is bound to a service.
local plugin_name = "odin-basic-auth"local schema = {type = "object",properties = {enable = { type = "boolean", default = true, enum = { true, false } },},}local _M = {version = 0.1,priority = 2802,name = plugin_name,schema = schema,}The enable flag is necessary because APISIX plugins can be bound to services, making it impossible to disable them per route without such a parameter.
function _M.check_schema(conf)local ok, err = core.schema.check(schema, conf)if not ok thenreturn false, errendreturn trueendfunction _M.access(conf, ctx)if not conf.enable then return endlocal headers = ngx.req.get_headers()if not headers.Authorization thenreturn 401, { message = "authorization is required" }endlocal username, password, err = extract_auth_header(headers.Authorization)if err then return 401, { message = err } endlocal res = authorizations_etcd:get(username)if res == nil then return 401, { message = "failed to find authorization from etcd" } endif not res.value or not res.value.id then return 401, { message = "user is not found" } endif res.value.password ~= password then return 401, { message = "password is error" } endendEtcd Cache Object
The plugin creates an etcd cache object during the init phase, enabling fast in‑memory reads while keeping data up‑to‑date via etcd watch.
local authorizations_etcdlocal appkey_scheme = {type = "object",properties = {username = { description = "username", type = "string" },password = { type = "string" }}}function _M.init()authorizations_etcd, err = core.config.new("/authorizations", { automatic = true, item_schema = appkey_scheme })if not authorizations_etcd then error("failed to create etcd instance for fetching authorizations: " .. err) endendPlugin API Definition
The plugin exposes a custom API to add or update authorizations in etcd.
function _M.api()return {{ methods = { "POST", "PUT" }, uri = "/apisix/plugin/basic-auth/set", handler = set_auth }}endlocal function set_auth()local username = req.get_str("username")local password = req.get_str("password")local key = "/authorizations/" .. usernamelocal res, err = core.etcd.set(key, { username = username, password = password })if not res then core.response.exit(500, err) endcore.response.exit(res.status, res.body)endcurl -i -X PUT 'http://127.0.0.1:9080/apisix/plugin/basic-auth/set' -d username=zhangsan -d password=hao123 -d user_id=3 -d action_ids=,1,2,3,Post‑Deployment Issues
Log files grew beyond the 50 GB quota, so we added cron and logrotate to the image and started the cron daemon in the container entrypoint to clean daily logs.
Acknowledgements
We thank the Apache APISIX contributors; see the official website and GitHub repository for more information.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
