Sau khi launch game lên App Store và Google Play, thứ đáng sợ nhất là nhận ra mình cần thay đổi gameplay balance hoặc bật/tắt feature — nhưng phải chờ review cycle 1-3 ngày của Apple mỗi lần. LiveOps system giải quyết vấn đề này bằng cách cho phép cập nhật game mà không cần release version mới.

Bài này trình bày kiến trúc LiveOps tối giản mà chúng tôi đã xây cho Cloud Ball — đủ để sử dụng thực tế mà không over-engineer.

LiveOps là gì và cần những gì?

LiveOps (Live Operations) là khả năng thay đổi nội dung, balance, và event trong game sau khi đã release — không cần update binary. Về cơ bản cần 3 thành phần:

  • Remote Config: File JSON trên server, game đọc khi khởi động để lấy các giá trị thay đổi được (damage, spawn rate, pricing...)
  • Event System: Định nghĩa event (Halloween, New Year...) với thời gian bắt đầu/kết thúc, rewards, và rules trên server — game tự activate/deactivate
  • Admin Dashboard: Giao diện web để thay đổi các giá trị trên mà không cần sửa code hay deploy lại server

Kiến trúc đơn giản nhất có thể

Thay vì dùng Firebase Remote Config (vendor lock-in) hay Unity Gaming Services (tốn tiền ở scale), ta tự build với stack tối giản:

  • Backend: Node.js + Express hoặc Fastify, PostgreSQL
  • API: REST endpoint đơn giản, authenticated bằng API key
  • Admin: Next.js hoặc plain HTML+JS dashboard
  • Unity client: UnityWebRequest + JsonUtility

Cấu trúc Remote Config JSON

{
  "version": 42,
  "gameplay": {
    "ballSpeed": 8.5,
    "gravityScale": 1.2,
    "maxBounces": 10,
    "comboMultiplier": 1.5
  },
  "monetization": {
    "adIntervalSeconds": 120,
    "rewardedAdCoins": 50
  },
  "events": [
    {
      "id": "summer_2025",
      "name": "Summer Festival",
      "startUtc": "2025-06-01T00:00:00Z",
      "endUtc": "2025-06-30T23:59:59Z",
      "active": true,
      "rewards": { "dailyBonus": 200, "specialSkin": "summer_ball" }
    }
  ]
}

Unity client: Fetch và cache config

// RemoteConfigManager.cs
public class RemoteConfigManager : MonoBehaviour
{
    private const string CONFIG_URL = "https://api.yourgame.com/config";
    private const string CACHE_KEY = "remote_config_cache";
    private const float CACHE_TTL_HOURS = 1f;

    public static GameConfig Config { get; private set; }

    void Awake()
    {
        // Load cache ngay để game có thể start
        LoadCachedConfig();
        // Fetch fresh config từ server
        StartCoroutine(FetchConfig());
    }

    IEnumerator FetchConfig()
    {
        using var req = UnityWebRequest.Get(CONFIG_URL);
        req.SetRequestHeader("X-API-Key", SecureStorage.GetApiKey());
        yield return req.SendWebRequest();

        if (req.result == UnityWebRequest.Result.Success)
        {
            var json = req.downloadHandler.text;
            Config = JsonUtility.FromJson<GameConfig>(json);
            PlayerPrefs.SetString(CACHE_KEY, json);
            PlayerPrefs.SetString(CACHE_KEY + "_time",
                DateTime.UtcNow.ToString("o"));
        }
    }

    void LoadCachedConfig()
    {
        var cached = PlayerPrefs.GetString(CACHE_KEY, "");
        if (!string.IsNullOrEmpty(cached))
            Config = JsonUtility.FromJson<GameConfig>(cached);
        else
            Config = GameConfig.Default; // fallback hardcoded
    }
}

Event System

Event được định nghĩa trên server, Unity client chỉ cần kiểm tra thời gian và active flag:

// EventManager.cs
public class EventManager : MonoBehaviour
{
    public static GameEvent GetActiveEvent()
    {
        if (RemoteConfigManager.Config?.events == null) return null;

        var now = DateTime.UtcNow;
        return RemoteConfigManager.Config.events
            .FirstOrDefault(e => e.active
                && DateTime.Parse(e.startUtc) <= now
                && now <= DateTime.Parse(e.endUtc));
    }

    public static bool HasActiveEvent() => GetActiveEvent() != null;
}

Để bật/tắt event, admin chỉ cần đổi "active": false trong dashboard — không cần touch Unity code.

Admin Dashboard

Dashboard tối giản nhất: một trang HTML + Fetch API để CRUD các giá trị config. Quan trọng hơn là authentication — không để dashboard public:

  • Dùng HTTP Basic Auth hoặc session-based auth với Argon2-hashed password
  • Rate limit endpoint edit (tránh brute force)
  • Audit log: ghi lại ai thay đổi gì, khi nào
  • Version increment tự động mỗi khi config thay đổi (để client detect)

Vấn đề thường gặp

Config không nhất quán giữa các device: Dùng version number trong config. Client chỉ apply config mới nếu version > version hiện tại.

Offline users: Luôn có fallback values hardcoded trong game. Cache là lớp thứ 2, server là lớp tốt nhất nhưng không bắt buộc.

A/B testing: Thêm userSegment field trong response dựa trên user ID hash. Mỗi segment nhận config khác nhau. Đơn giản nhưng đủ dùng cho game indie.

Kết luận: LiveOps không cần phức tạp để có hiệu quả. Với kiến trúc trên, bạn có thể thay đổi balance, bật/tắt event, và điều chỉnh monetization trong vòng vài phút mà không release version mới.

← Về danh sách Blog Liên hệ tư vấn →