Design Container Assignment with Incompatible Goods
FlexportSoftware Engineer · OnsiteLast updated
Design a shipment-planning and container-packing service that assigns cargo items to ocean containers subject to physical dimensions, weight limits, and hazardous/incompatibility rules while supporting async workflows and plan approvals.
Scenario
In ocean freight consolidation, freight forwarders pack cargo bookings from multiple shippers into standardized ocean containers (e.g., 20ft/40ft standard, high-cube, reefer). Items vary by dimensions, weight, stackability, and regulatory classifications (such as IMDG hazardous material classes). Certain goods cannot be co-loaded in the same container (e.g., flammable liquids cannot be placed with oxidizers or food products).
Design a container-assignment planning service that assigns cargo to containers while minimizing total container costs, enforcing hard physical and safety constraints, and allowing human operators to inspect, override, and approve plans.
Requirements
Functional Requirements
- Optimization & Constraint Enforcement: Given a manifest of cargo items and available container types, compute container assignments satisfying volume, weight capacity, and pairwise/group incompatibility rules.
- Asynchronous Planning: Optimization jobs must run asynchronously with polling or webhook notifications for status.
- Deterministic Results: Given the exact same inputs (manifest, container types, rule versions, and configuration seed), the solver must produce identical container assignments.
- Explainable Infeasibility: If a set of items cannot be legally or physically packed, the service must return actionable explanations identifying the conflicting items or violated constraints.
- Drafts, Overrides, and Approvals: Generated plans are saved as drafts. Operators can manually move items between containers (validated against safety constraints) and approve the final plan.
- Stale-Input Protection & Concurrency: Prevent approving or finalizing a plan if underlying cargo details changed during solver execution or operator review.
- Auditability: Maintain an immutable history of input revisions, solver outputs, manual edits, and approval actions.
Non-Functional Requirements & Scale
- Scale: 15,000 shipment planning requests per day; up to 100 concurrent optimization runs.
- Job Size: Typical plans contain 50 to 500 items; large multi-supplier consolidations contain up to 5,000 items.
- Execution Time: Under 30 seconds for standard plans (p95); under 2 minutes for 5,000-item plans.
- Data Consistency: Strict consistency on plan approvals and inventory locking to prevent double-allocating cargo or containers.
What Your Design Should Cover
- API Design: Key endpoints for submitting plan requests, checking progress, retrieving explanations, overriding assignments, and approving plans.
- Data Model: Schemas representing Cargo Items, Incompatibility Rules, Container Specs, Plans, Assignments, and Audit Logs.
- Architecture: Decoupled async job processing, solver workers (e.g., integer programming/constraint programming), and caching/storage tiers.
- Concurrency & Correctness: Handling race conditions between concurrent operator edits and manifest updates using optimistic concurrency control (OCC) or hashing.
- Explainability & Conflict Resolution: Strategy for identifying minimal conflicting subsets when a manifest cannot be fully packed.
Hints
Hint 1
Decouple the synchronous API layer from the compute-heavy optimization engine using a message queue, worker pool, and distributed task status tracker.
Hint 2
Use optimistic locking with input manifest hashes and plan version IDs to detect if cargo attributes changed between job initiation and plan approval.
Hint 3
For explainability, model incompatibility constraints such that solver engines (e.g., CP-SAT or SAT solvers) can extract a Minimal Unsatisfiable Core (MUC) when no feasible solution exists.
Follow-up questions
- How would you extend the solver to optimize for 3D load stability (axle weight distribution and center of gravity) alongside compatibility?
- If an operator needs to split an infeasible manifest across multiple shipments with different departure dates, how does your system recommend optimal partition boundaries?
- How do you handle zero-downtime updates to regulatory incompatibility rules without invalidating or silently corrupting in-flight draft plans?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.